Common BoardPlease some body tell me why i am gettig wrong answer in this. My code is: #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <string.h> #include <cstdlib> #include <sstream> #include <stack> #include <queue> #include <numeric> #include <utility> #include <cctype> #include <list> #include <climits> #include <signal.h> #include <ctime> #include <map> #include <set> using namespace std; #define ll long long int ll i, j, k, ct=0, m, n, t, x, y, z, tc, a[200000],s; vector<ll> ans; int main(){ cin >> n >> s; for(i = 0; i < n; i++){ cin >> a[i]; } sort(a,a+n); for ( i = n-1; i > 0 ; i-- ) { if ( a[i] + a[i-1] <= s ) { break; } } // cout << x << " " << y << endl; if(s%2==0){ x = i+1; y = i; //z = n-1; while ( x < n && y >= 0 ) { ans.push_back( a[y] ); ans.push_back( a[x] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } else { y = i; while ( i < n && a[i] == a[y]){ ans.push_back( a[i] ); i++; } y--; x = i; while ( x < n && y >= 0 ) { ans.push_back( a[x] ); ans.push_back( a[y] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } ct = 0; for ( i = 0; i < ans.size(); ) { if( i == ans.size() - 1){ ct++; i++; } else{ if( ans[i] + ans[i+1] <= s){ ct++; i+=2; } else{ ct++; i++; } } } cout << ct << endl; for ( i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } return 0; } Edited by author 13.10.2012 20:42 My god! When I use gcc I get the right anwer, but vc++2010 doesn't. What should I do? There is still time left in the competition...? I have a problem with test 2 too Edited by author 14.10.2012 00:59 сам ни до конца понял я условие понял, но ва6. Edited by author 14.10.2012 00:59 числа из отрезка подходят под нормальный сигнал! Edited by author 14.10.2012 00:59 I solved this problem on Pascal and was AC. But i wrote same program on C and C++. It gives same answers on same tests on my machine but gives WA on test 1 when i submit. These my programs: On pascal:: var a:array[1..10000] of integer; k,n,m,i:integer; s:longint; procedure cle; var i:integer; begin for i:=1 to n do a[i]:=0; end; begin read(n,m); cle; s:=0; for i:=1 to m do begin readln(k); if k<>0 then inc(a[k]); end; for i:=1 to n do begin if a[i]<>0 then writeln(a[i]/m*100:2:2,'%') else writeln('0.00%'); end; end. On C: #include <stdio.h> void main(){ int k,n,m,i; int a[10000]; scanf("%d %d\n",&n,&m); for (i=1;i<=n;i++) a[i]=0; for (i=1;i<=m;++i){ scanf("%d",&k); if (k!=0) a[k]++; } for (i=1;i<=n;++i){ if (a[i]!=0) printf("%2.2f%\n",(float)a[i]/m*100); else printf("0.00\n"); } } 1) Use "double" instead of "float". 2) Don't use Pascal, 'cause C++ is really cool language. P.S. I don't understand how can people write theese "begin ... end" so many times? I don't understand people who think they are cool enough to speak such foolish things ;) Pascal is not worse than C++, and it is up to one to choose what language to use - as for me I use Pascal and I am in Top 10 :) Safe Bird uses C++ - but he does not scream that C++ is better... P.S. Sorry, can not control myself when Pascal in under attack ;) RESPECT++++++ PASCAL RULEZZZ!!!! Hmm... Pascal is not spported at World Finals now. Best programmers have started using Java. Maybe Timus must do the same - substitute Pascal to Java. Don't you want to double all timelimits for "fast" Java programs to pass them? :))) oooh. Yesss. Java is good. I will glad if timus add Java compiler to this contest "Pascal is not spported at World Finals now" - с этого года что ли? Pascal provided but not supported read this: http://icpc.baylor.edu/systems/finals/pascal.htm Pascal will not be removed from Timus of course. Java will be added as soon as possible, but not to February, 11. It is possible to recalculate all timelimits for Java. But it is impossible to make all problems solvable in Java. Edited by author 04.02.2006 15:05ACM.Tolstobrov_Anatoliy[Ivanovo SPU] :) [1] // Problem 1263. Elections 4 Feb 2006 18:58 deleted Edited by author 26.10.2018 14:38 deleted Edited by author 26.10.2018 14:37 And why it is problem to solve it in Java? What we need for solution - just one array int[1000] But I really don't understand why timelimit is so small - memory is not crucial part of this problem at all... memory is not crucial part of this problem at all... Maybe author wanted to cut off DP way of solving this problem or something like this. I did't say that Pascal is bad, nasty, ugly, damned language or something like it. But... U must agree with me that up to now there is no compiler for Pascal that can be compared with MVC++ or g++. Theese make really good machine code. :) And IMHO this language is uncomfortable to write algorithms and serious projects. What for Top 10... over some year Top 10 or even Top 50 can became consisting only of Pascal (or - that's terrible - Java) users. Even BASIC coders could be cool because they ARE cool. You think we prefer language? Often programming language prefers us. Pascal is popular in Russia just because of traditions begun with 80's. P.S. I accept your apology, but "LOL" is offensive, don't you think? ДИМАН VERY GOOD MAN, НАПИСАЛ LOL, НАПИШИ ЕМУ ТАКЖЕ:) I suggest to make a voting. I use pascal about 5 years for solving problems. And as for me, I think that pascal is not so uncomfortable to write algorithms. Edited by author 07.02.2006 21:39 Hi! I'm first time here and seems the last - cause there is no Java support. Are you going to add it soon? Pascal is the worst language I ever seen..... Shut up! Pascal Will Newer Die! Edited by author 18.10.2006 08:05 In C++ very hard syntax, and Pascal is good language too Currently I'm using C++ for solving problems, but can say: Pascal foreva! C++ has many drawbacks which are worse than just long "begin .. end" I solved problems using all languages available on this server and Java seems to be most convenient for me.. #include <iostream> #include <stdio.h> using namespace std; int main() { int br[10024],i,m; double n,a; float sum; cin>>n>>a; sum=100/a; for(i=1;i<=10024;i++) { br[i]=0; } for(i=1;i<=a;i++) { cin>>m; br[m]++; } for(i=1;i<=n;i++) {
printf("%.2lf",(br[i]*sum)); cout<<"%"<<endl; } return 0; } 1) Look how your C++ program will work with n=10000;) 2) You've forgotten about percent sign in else printf("0.00\n"); 3) Don't use % in printf, use %% (it will show as %) 4) LEARN C++ well before writing on it! Edited by author 03.02.2006 17:57 >> 2) You've forgotten about percent sign in else printf("0.00\n"); Is it really necessary? Can anyone translate my solution below into C++? I want to learn programming in C/C++ too :) type TArray=array of dword; var arr:TArray; m,n,c,i:dword; begin readln(n,m); setlength(arr,n+1); for i:=1 to n do arr[i]:=0; for i:=1 to m do begin readln(c); arr[c]+=1; end; for i:=1 to n do begin writeln((arr[i]*100/m):2:2,'%'); end; end. if input is sample input,can output be : 2 3 6? And why?thx Yup, output is correct, because 3 is a friend with 1, 2, 4, 5 and 6 is a friend with 7. So each member of each team has at least one friend in the opposite team Yup, output is correct, because 3 is a friend with 1, 2, 4, 5 and 6 is a friend with 7. So each member of each team has at least one friend in the opposite team wtf? why 6 and 7 are friends? this problem don't only a result!!! How can we make this results -- 0.001 sec -- 1 128 KB ? This is the best result for this problem. I wonder how can we get this results. You can see this result by clicking the link Solution Rating on problem statement. :: http://acm.timus.ru/rating.aspx?space=1&num=1290 :: Edited by author 08.10.2012 12:45 Edited by author 08.10.2012 12:46It is not possible to achieve 0.001 sec result with the current judge. The measurement for an empty program that only calls puts("\n"); is 0.015 at this time. Until the measurement mechanism is changed, those who submitted results years ago will be the only ones to achieve 0.001. Give 9 test please. Edited by author 12.10.2012 14:16 Edited by author 12.10.2012 14:16 My program print this result: 9 212122112 1.Pay attention 0 < ai < bi < 1e9. (I forgot the 0 and 1e9 axis...then wa teat 2 for many time) 2.The data of test 3 maybe 1 1 1000000000 b answer: 0 1 I make an error while recursion to the leaf note. I return the l index instead of the axis it map to. T T Edited by author 11.10.2012 19:04 Angles must be strogly acute? I.e., right angles (pi/2) are restricted? See first sample. It is now absent, but before the sample was corrected there was right angle... My AC solution rejects right angles I got AC when I deleted right angles. I had WA before that. It seems timing has changed since the earlier years on the server. When the following program gets WA in 0.015, you know 0.001 is not possible any more: #include <stdio.h> int main() { puts( "0" ); } Too bad that those of us solving problems now don't get time rated on the same scale as those who came before. But if your code work 0.5 now, in 2003 he worked more than 1 sec The fact that computers are faster today is not the point. In fact, it makes the 0.015 vs. 0.001 difference even more crazy -- computers today are *not* 15 times slower than in 2003! Obviously it is a difference in time measurement technique or a system difference that causes the measurements to differ. When such a measurement difference occurs, all problems should be re-rated for time, it's impossible to compete for time rating on O(1) problems when the fastest possible measurement today for an empty program is 15 times greater than it used to be. must I roped off all the nails with shortest rope? Use the formula: N=[a+(a+p-1)]*p/2,and you will got the formula of A: A=[ 2*N/P +1-p]/2 Loop p to find A,that's what someone else in this forum suggested. But even in this way some people got TLE as well.I guess you start looping P from 10^9... In fact you can find that 2N/P +1-P >0,solve this inequality,you will find p is <[1+sqrt(1+8N)]/2. You can cut the time of the loop down to half or even less in this way. I can't understand you I'll explain it to you in Chinese tomorrow...How did you find my post? this problem has solution O(sqrt(2N)) 'cause 2N = P(2A+P-1) N, P, A is natural, so P is divider of 2N, so algo is simple scan N, multiply N by 2, then for each divider of this new N less then sqrt(N) try to find p = divider or n / divider, a = (a - p + 1) / 2, where a supposed to be natural, if out p bigger than our saved one - replace saved one. out our bigger result Loop P from 44720 downto 1 and check out these two conditions to be true: 1) N>=P(P+1)/2; 2) P divides (N-P(P+1)/2). Break as fast as you find the first one. Then A=1+(N-P(P+1)/2)/P. If you still can't get it, look at the following lines. 1+2+3+4+5=15 2+3+4+5+6=20 3+4+5+6+7=25 4+5+6+7+8=30 Et cetera. >var n,k,ans1,ans2:longint; > >begin > read(n,k); > if n<k then write('0') else begin > ans1:=(n div k)*(n + n mod k); > ans2:=(n-k)*4; > if ans1>ans2 then write(ans1) else write(ans2); end; >end. My program is very short. My method is like yours and I can't find the bug in it. What was wrong with yours? For 8 3 answer is 21, not 20 I’ve AC, but I still have a question! My first program used “unsigned long” type, and didn’t pass Test 12 Then I changed all types to “unsigned long long” , and program was AC. So, my question is why my first program failed on Test12? As you know n,m<=2^31-1;So, the biggest result is 0xFFFFFFFD! This result can be represented by unsigned long! So, I didn’t announce my program, because it is bad style. I’m sure that those programmers who solved this issue can understand my question…. Best Wishes, Veniamin. Each of n and m is <= 2^31-1. Yes, they are unsigned long. But max unsigned long + 1 is? Overflow, of course !! Your solution doesn't print n or m exactly but you have to calculate either 2*m or 2*n, aren't you? Thanks.I also meet this question. > here is my source (C++): --------------------------- #include <stdio.h> int i;long sum=0; int n; void main() { scanf("%d",&n); if(n<1) for(i=1;i>=n;i--) sum+=i; else for(i=1;i<=n;i++) sum+=i; printf("%ld",sum); } -------------------------- Try to delete void because i did so , and my programm was right good Luck ! can you say which alhoritm it is? topologial sort? |
|