Common BoardWhat is wrong with this? Help me please. ))
#include<vector> #include<cmath> //#include<conio.h> using namespace std; int main() { unsigned int i, n; unsigned long k; vector<char>a; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%U", &k); if (sqrt(8 * k - 7) - floor(sqrt(8 * k - 7))) a.push_back(0); else a.push_back(1); } for(int i =0; i < a.size(); i++) printf("%d ", a[i]); //getch(); return 0; } Thanks )) This test helped me get AC (i had access violation at test 12): 3 1 0 2 2 0 3 Good luck. is the answer 1 3 2 YES, your answer is correct also 1 2 3 correct too. this test help me, i hope it's help you too: input: 3 0 0 0 0 0 0 output: 1 2 3 or 1 3 2 or 2 1 3 or 2 3 1 or 3 1 2 or 3 2 1 sorry for my poor english. GOOD LUCK!!! you should suggest that ?!.....?!!... are not the amount of sentences but only 1 end of the sentence. for example sentence "Aaaa? !" doesn't have some errors. "? !" - is one end of the sentence... i use O((n-1)!* n^2) and got AC in 0.109 s. just use o(n^2) memory. for all permutation check its valid or not, for example for this test: 4 3 1 2 2 3 3 4 the permutation 1 2 3 4 is valid but 1 3 4 2 is nonvalid. GOOD LUCK!!! I have run my program on my own conputer (which is slower than the server) several times on the data N = 50000. It takes not more than 0.1 seconds every time. My algo is DP with the Time Complexity O(N). To make my program robust, I use QuickSort to sort the edges, and this might use O(N log N) time. I don't know why I get TLE. Maybe there are some tricks? Thanks in advance. By the way, I have submitted my program many times, and tried to crash it many times. I realised that test #17 has N = 50000, too. And my program use not more than 0.3 sec to pass it. Why do I get TLE at test #23? Please help me, thx in advance. Edited by author 15.09.2010 12:04 I have found the problem. The QuickSort procedure in my problem works quite slow in the OJ. I don't know why. First #23 then #25. At last, I use a random method in the QuickSort and get AC, only 0.078 sec. BTW, this is the first time I got stuck in QuickSort in TIMUS. Congratulations... > The QuickSort procedure in my problem works quite slow in the OJ. I don't know why. It's not the matter of OJ environment but the matter of corner cases. Note that asymptotic complexity of QuickSort in worst case is O(n*n). i dont use quick-sort and use one bfs only, why my program have 0.265 s, in time??? var p,q,q1:real; i,p1:integer; f:boolean; begin read(p); read(q); p:=p/100; q:=q/100; f:=true; i:=1; while f do begin inc(i); p1:=trunc(p*i)+1; q1:=q*i; if (p1<q1) then f:=false; end; writeln(i); end. I don't understand it too. I have like code var m,n,i,k:integer; begin readln(n,m);k:=0; for i:=n to m do if odd(i) then inc(k); writeln(k);readln; end. I'd say this is a brute force. Here is mine AC: var a,b,c:integer; begin readln(a,b); c:=(b-a+1) div 2; if (odd(b)) and (odd(a)) then inc(c); writeln(c); end. Why do you post your ACC programs here ? This is a bad practice. Edited by author 19.07.2006 16:22 This is shorter b shr 1 - a shr 1 + b and 1 (b - a) / 2 + (a % 2 | b % 2) My code is: {$apptype console} uses sysutils; var number:string[100]; buf,buf2:string; i,n,k:0..50000; a:array[1..100,1..2]of string; //ñëîâàðü b:array['a'..'z'] of char; procedure set_b; begin b['i']:='1'; b['j']:='1'; b['a']:='2'; b['b']:='2'; b['c']:='2'; b['d']:='3'; b['e']:='3'; b['f']:='3'; b['g']:='4'; b['h']:='4'; b['k']:='5'; b['l']:='5'; b['m']:='6'; b['n']:='6'; b['p']:='7'; b['r']:='7'; b['s']:='7'; b['t']:='8'; b['u']:='8'; b['v']:='8'; b['w']:='9'; b['x']:='9'; b['y']:='9'; b['o']:='0'; b['q']:='0'; b['z']:='0'; end; procedure translation; begin for k:=1 to n do begin setlength(a[k,2],length(a[k,1])); for i:=1 to length(a[k,2]) do a[k,2,i]:=b[a[k,1,i]]; end; end; procedure seeking(f:integer); var i,leng,leng2:integer; begin i:=1; while (i<=n)and(buf2<>number) do begin if pos(a[i,2],number)=f then begin leng:=length(buf); leng2:=length(buf2); buf:=buf+a[i,1]+' '; buf2:=buf2+a[i,2]; if buf2<>number then seeking(f+length(a[i,1])); if buf2<>number then begin setlength(buf,leng); setlength(buf2,leng2); end; end; inc(i); end; end; begin set_b; repeat buf:=''; buf2:=''; readln(number); if number='-1' then exit; readln(n); for i:=1 to n do readln(a[i,1]); translation; seeking(1); if buf2=number then writeln(buf) else writeln('No solution.') until false; end. i use O(nlogn) and got AC, if you use O(N) for this problem, plz tell your algo to me. sorry for my poor english. #include<stdio.h> #include<math.h> //#include<conio.h> void main(){ //clrscr(); double i; // unsigned long num; double range=pow(10,18); while((scanf("%lf",&i))){ if(i<0) break; if(i>range) break; printf("\n%.4lf",sqrt(i)); } //getch(); } what is wrong in my code can anyone please tell Edited by author 20.11.2010 14:47 double i=0; double nums[100000]; while((scanf("%lf",&nums[i])!=EOF){ i++; while(i>=0){ printf("\n%.4lf",sqrt(nums[i]); i--; } Now i am getting array size is too huge and i even tried dynamic allocation and it doesnt work.. I am using turbo C++ Version 3.0 compiler. Please help me with this Please help guys!!!!!!!!! del Edited by author 06.12.2010 14:41 Tests can violate constraints of input data? What must happen in case of violation? -------------------------- P.S. Sorry for my "English" ) Can somebody give me hint about this testcase. Thanks!!!! Edited by author 05.12.2010 23:32 I've got AC on this solution. This solution isn't bruteforce #include <iostream> using namespace std; int* sort(int*, int); int main() { int N; cin>>N; int *W = new int[N]; for(int i=0;i<N;i++) { cin>>W[i]; } sort(W,N); int pipe1=0; int pipe2=0; int weight=0; for(int i=0;i<N;i++) { weight+=W[i]; } for(int i=0;i<N;i++) { if((pipe1+W[i])<=weight-W[i]) { pipe1+=W[i]; weight-=W[i]; } else { pipe2+=W[i]; weight-=W[i]; } if(pipe1<pipe2) { int temp=pipe1; pipe1=pipe2; pipe2=temp; } } cout<<pipe1-pipe2; return 0; } where sort()is back ordered sort Fails on { 2, 2, 3, 4, 5}. Should be 0 ({2, 2, 4} - {5, 3}), but returns 2 ({5, 2, 2} - {4, 3}). Could you please give me a hint? Do we need to generate a fibonachi digits in any way or there is a better solution? same question. I wrote the solution: 1) generate fib one by one and sum digits. 2) very optimize actions and no copy array of digits 3) stable sort or count sort ==> it works on test "2 50000" about 4 - 5 second. TL 12 How did you avoid TL? 1. Generate all sums of digits for numbers from 0 to k^p-1 (the best p is 6 for my solution) 2. Replace k with k^p 3. Run stupid solution but add precalculated numbers to sum 4. ??????? 5. PROFIT accepted... How can i generate Fibonchi num 50000? it is very big! Use long arithmetics. So in the worst case i must calculate the 50000 Fibonachi numbers, writing them using long arithmetic, at the same time calculating the number of banknotes to pay for them, writing this calculations in separate array. Then i must sort this array and print the bounded numbers of sorted elements from begin to the end. Is this method ok? This method gets TLE, but it may be improved (look at my previous messages). Thx... Will try to calculate the number of banknotes using precounted values... Guys, could you please send me your code for investigation? kobchik83@list.ru THANKS A LOT FOR YOUR HINT !! THANKS A LOT FOR YOUR HINT !! Edited by author 04.12.2010 21:54 you must determine the minimum distance from the AB segment not AB line. input: 1 2 1 1 0 0 0 output: 1.41 2.24 sorry for my poor english. GOOD LUCK!!! Edited by author 04.12.2010 17:17 |
|