Общий форум> Who knows, who knows... > > Who knows, who knows... TEST: 9999 14 ANSWER: 1 10000 10000 My OS: Linux Ubuntu 10.10 I use gcc 4.4.5 (don't have OS Windows) On my computer no errors and warnings Program source: #include <iostream> #define abs(x) ((x)<0 ? -(x) : (x)) using namespace std; int main() { short n; long sum = 0; long firstSum = 0; long secondSum = 0; cin >> n; long w[n]; for(int i=0; i<n; i++) { cin >> w[i]; sum+=w[i]; } sum>>=1; long temp = w[0]; int num = 0; for(int i=0; i<n; i++) { if(temp<w[i]) { temp = w[i]; num = i; } } firstSum+=temp; w[num] = 0; for(int i=1; i<n; i++) { num = 0; while(w[num]==0) { num++; } temp = w[num]; for(int j=0; j<n; j++) { if((temp>w[j])&&(w[j]!=0)) { temp = w[j]; num = j; } } w[num] = 0; if(firstSum+temp<sum) { firstSum+=temp; } else { secondSum+=temp; } } cout << abs(firstSum-secondSum) << endl; return 0; } A got AC using real numbers with EPS = 1e-8, so precision is not major matter here... i think it is safe to rotate point 1 90 degrees 4 times and check if it is possible to align the rotated point 1 with point 2 to form an edge of the square. rotated point1 will also have integer coordinates. Thanks, Neal Zane! Your idea is fruitful indeed. I've already gave up to overcome test#24, where float calculations seem to be very sensitive to precesion. And tan/atan along with sqrt gave me error of 10^-8. Now totally integer solution is concise and fast! Thanks for idea. Simple and beautiful. My previous AC solution was more difficult. I have tried this way. When I used the formula 2*(y0*x1 - y1*x0)^2 ? R^2*((x1 - x0)^2 + (y1 - y0)^2) (with 3 x <- -y, y <- x) (with long long on right side) has received WA 3. My previous right solution with use of floats has no more lines and operations. Therefore I believe that geometrical problems to solve in the habitual ways (via floats with epsilon) more preferably. It is necessary to use a "wheel", instead of to invent something new when good average speed of the decision of a problem is necessary. I was very surprised, when after WA1 and WA 2 my solution was accepted :) Pay attention to the situation, when points becomes the same. Pay attention to the situation, when points becomes the same. Thanks! Very useful hint! Yes, random work. My solution ~ 0.5s. Choose three random points and count points inside circle. Maybe weak tests... Edited by author 27.01.2011 00:28 Hi Experts, Can you suggest how to approach solving such problems. I am getting no clues at all. Moreover we know nothing about total number of spaces in the text. regards Anupam If you have a group with N spaces and apply to it the operation, that changes K spaces to one, then the number of spaces will be N/K + N%K. You should output such numbers K[1], K[2], ... , K[m], that for every number N in range [1..L] a sequence of operations N := (N/K[i] + N%K[i]) for each i = 1..m will make the value N equals 1. And then you should maximize the range for N. I guess it is a school problem :) Edited by author 25.01.2011 20:42 Edited by author 25.01.2011 20:43 Anyone help me to understand or solve this problem.I didn't understand how comes the answer 3837 The limitations in the problem statement were decreased. New limitations are W, H ≤ 500; D ≤ 1000. Tests were fixed according to these limitations. New tests were added. All submits were rejudged. 5 submits got AC verdict, 41 submit lost AC verdict. Thanks to Sergey Vedernikov and Roman Rizvanov for new tests No subject Edited by author 25.01.2011 00:20 What is test 5? I can't find my mistake. Edited by author 24.01.2011 16:15 Edited by author 24.01.2011 16:15 My code: #include <stdio.h> void printdw(int* f1, int *f3, int d, int dd, int lim) { int f2=0; if (d==1 || *f1==1) { if (dd==d) {printf(" [%2d]", d); f2=1;} else {printf(" %2d", d);} *f1=1; } else { if (dd==d) {printf(" [%2d]", d); f2=1; *f1=1;} else {printf(" %2d", d);} } for(d+=7; d<=lim; d+=7) { if (f2==1) {printf(" %2d", d); f2=0;} else { if(d==dd) {printf(" [%2d]", d); f2=1;} else printf(" %2d", d); } } if (d==lim+7) *f3=1; if(d<lim+7 && *f3) { if (!f2) printf(" "); else printf(" ");} printf("\n"); } int main() { int dd, mm, yy, dw, lim, f1, f2, f3, d; scanf("%d %d %d", &dd, &mm, &yy); dw=(6+yy-1600+((yy-1)/4-399)-((yy-1)/100-15)+((yy-1)/400-3))%7; if (mm==5) dw++; if (mm==8) dw+=2; if (mm==2 || mm==3 || mm==11) dw+=3; if (mm==6) dw+=4; if (mm==9 || mm==12) dw+=5; if (mm==4 || mm==7) dw+=6; if (mm>2) { if (!(yy%4)) dw++; if (!(yy%100)) dw--; if (!(yy%400)) dw++;} dw%=7; if (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12) lim=31; else { if (mm!=2) lim=30; else {if (yy%4 ||(!(yy%100) && yy%400)) lim=28; else lim=29;} } f1=0; f3=0; printf("mon"); d=(8-dw)%7+1; printdw(&f1, &f3, d, dd, lim); printf("tue"); d=(d+7)%7+1; printdw(&f1, &f3, d, dd, lim); printf("wed"); d=(d+7)%7+1; printdw(&f1, &f3, d, dd, lim); printf("thu"); d=(d+7)%7+1; printdw(&f1, &f3, d, dd, lim); printf("fri"); d=(d+7)%7+1; printdw(&f1, &f3, d, dd, lim); printf("sat"); d=(d+7)%7+1; printdw(&f1, &f3, d, dd, lim); printf("sun"); d=(d+7)%7+1; printdw(&f1, &f3, d, dd, lim); } Please! help to find mistake! Edited by author 24.01.2011 17:54 Ma prietenule! Ce mai faci? Vrei sa ma iubesti? Edited by author 24.01.2011 11:02 Does any one know that case? Edited by author 24.01.2011 10:45 Greetings! I've been reading FAQ about C# and noticed, that memory boundaries aren't specified via command-line arguments (as they are in Java). Isn't it a secret, how Timus team manage to set memory limits for c# then? // The thing is that I will be first-time helping with organization of some contests in our region, so my interest has a practical nature. :-) I do not understand when you have finished receiving data, and that if no effect then enter receive data never end, so never would show the results and would be an endless repetitive cycle. now with that key, or as I have to request new data, since no effect enter then I have no idea how to stop the cycle does not specify how to stop it. greetings. have you tested your program on your machine? How can we use eof without opening file?? WTH with it? I can't understand anything! FPC 2.0 doesn't compiling it. And Embarcadero RAD Studio XE too! So, What The Hell with it? Here's my solution : - Input & reverse all the edges - DFS from all vertexs - If depth = N then output in reverse order What's wrong w/ this one ???? the graph may be not connected. I was WA#2 and now I get Ac, because: Graph can be not connected I got WA#2 too, but I thought that the graph is supposed to be not connected. Can help me identify my errors , here's my solution : - I reverse all the edges - DFS from the vertex without any other vertex pointing to - Count the depth, if depth = number of vertex -> output in reverse order 3Q,i made the same mistake,and i now get AC i have written algorithm that uses log2() which is in c++(<cmath> library) and when i used it copmpilation error occured "error C3861: 'log2': identifier not found" when i compile it in devc++ it works perfectly.. can everyone helm me? :( Timus use the compiler visual c++ compiler not gcc. hint: log2(n) = log(n)/log(2) (but this sum at the complexity) Edited by author 21.01.2011 22:32 Edited by author 21.01.2011 22:32 Timus use the compiler visual c++ compiler not gcc. hint: log2(n) = log(n)/log(2), (but this sum at the complexity) |
|