Общий форум\u002f\u002a public class Main {} \u002a\u002f \u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0069\u006f\u002e\u002a\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0075\u0074\u0069\u006c\u002e\u002a\u003b\u000d\u000a\u000d\u000a\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u004d\u0061\u0069\u006e\u0020\u007b\u000d\u000a\u000d\u000a\u0009\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u0020\u0069\u006e\u003b\u000d\u000a\u0009\u0050\u0072\u0069\u006e\u0074\u0057\u0072\u0069\u0074\u0065\u0072\u0020\u006f\u0075\u0074\u003b\u000d\u000a\u0009\u000d\u000a\u0009\u0076\u006f\u0069\u0064\u0020\u0073\u006f\u006c\u0076\u0065\u0028\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0069\u006e\u0074\u0020\u0061\u0020\u003d\u0020\u0069\u006e\u002e\u006e\u0065\u0078\u0074\u0049\u006e\u0074\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u0069\u006e\u0074\u0020\u0062\u0020\u003d\u0020\u0069\u006e\u002e\u006e\u0065\u0078\u0074\u0049\u006e\u0074\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0061\u0020\u002b\u0020\u0062\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u000d\u000a\u0009\u0076\u006f\u0069\u0064\u0020\u0072\u0075\u006e\u0028\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0069\u006e\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u0028\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u0069\u006e\u0029\u003b\u000d\u000a\u0009\u0009\u006f\u0075\u0074\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0050\u0072\u0069\u006e\u0074\u0057\u0072\u0069\u0074\u0065\u0072\u0028\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u0029\u003b\u000d\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0073\u006f\u006c\u0076\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u0020\u0066\u0069\u006e\u0061\u006c\u006c\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u006f\u0075\u0074\u002e\u0063\u006c\u006f\u0073\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u007d\u000d\u000a\u000d\u000a\u0009\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0061\u0072\u0067\u0073\u005b\u005d\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u006e\u0065\u0077\u0020\u004d\u0061\u0069\u006e\u0028\u0029\u002e\u0072\u0075\u006e\u0028\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u007d Could you please check my submissions. The accepted one (I actually copy-pasted it from this forum) gives wrong answer to the following data set: tram (only 4 symbols in input.txt file) The output is "Bus driver". My original solution (#4725054) gives "Tram driver" answer to the mentioned data set, but fails on test #6. Can you please give information what is wrong with this test? Thank you. Last line of input data is always terminated with end of line character (it is the usual rule of Timus Online Judge), so this test is incorrect. Ok, got this. So I assume the problem is on my side. Will try to find what is wrong Just use diagonal painting: 1 2 3 ... k ... (total n times) 2 3 4 ... 1 ... (total n times) . . . ... . ... (total n times) Calculate, how many 1,2, ... k in this table. Answer will be minimal of them(every rectangle 1xK covers K different colors). I don't no is this mathematically correct, but this solution got AC. Don't forget, that if N < K answer is 0. P.S. Sorry for bad English. > Just use diagonal painting: > 1 2 3 ... k ... (total n times) > 2 3 4 ... 1 ... (total n times) > . . . ... . ... (total n times) > Calculate, how many 1,2, ... k in this table. Answer will be minimal > of them(every rectangle 1xK covers K different colors). > I don't no is this mathematically correct, but this solution got AC. > Don't forget, that if N < K answer is 0. > P.S. Sorry for bad English. email me: caa@baga.ac.net.ru >>> vasilisk_voin@mailru.com Can anybody give me example for this table?Please... For example what table will be if n=5 k=3 ? if N=5 and K=3 the correct answer is 8 but not 7. To see the solution don't use the square (3,3) in the 5*5 grid Edited by author 13.11.2005 13:39 Edited by author 13.11.2005 13:39 Why such found minimal value really achivable in all cases? its because for each number in the table there you can put 1*K piece so that it won't intersect with others.And answer is minimum value because each piece lays on K diffirent numbers so you can't put more pieces that numimum value of 1...k PS. Thanks! It's really easy to solve with O(1) time with your tips! This is only your belive... Told property has only minimal number. THE PROOF 1) if you "stack" the coffins, you use up all of the graveyard, except for N%K square in the corder. 2) if you "spiral" the coffins, you leave N-2(N%K) square in the middle after the first spiral, N-4(N%K) square after the second spiral, until you use up all of the graveyard, except for (N-2(N%K))%K square in the middle. (N-2(N%K))%K = (-N)%K = K-N%K 3) if we use the better of the two strategies, we use up all of the graveyard, except for M=min(N%K, K-N%K) square. How many colors will it have? The first row will be colored 1..M, the second 2..M+1, the last M..2M-1 All K colors will be present iff 2M-1>=K 4) M=min(N%K, K-N%K) guarantees M<=K/2 Therefore, the remaining square will not have all K colors. This proves that using the better of the two strategies exhausts at least one of the K colors, QED. please tell your idea more in detail thanks, i got AC when i use your idea. but i dont why it's true? who's know?
Can you generate me some tests with answers? I'd like to check my program. Put R+,Q+. Try this: 1000000 1000000 1000000 1000000 1 1000000 1000000 999999 1000000 3 1000000 0 1 1000000 2 I think that answer on the last test must be 3. (1+1000000i)*(-i)+i=1000000 (1+1000000i)*(1-i)-1-999999i=1000000 (1+1000000i)*0+1000000=1000000 Some random tests: 21 56 32 45 3 90 87 45 23 4 234 876 129 623 2 12345 65 8967 1345 3 4563 897 156 734 4 4 6 7 8 3 4 3 3 1 2 4 2 2 3 2 3 4 3 27 1 0 15 4 0 45 4 0 my solutin gives "4 4". But still WA#15 my solution also gives "4 4". But still WA#15, what can i do? Hi, guys! In the problem statement input is a string, that consists of a..z or A..Z. Let me guess, Test 7 has some other chars ? If so, please, correct prom statement with this note. 4 my submissions were with WA#7 until I added char check Test 7 consists of characters a..z and A..Z only. I had the same situation as topic starter. Maybe there is '\n' at the end of the test #7. #include<cstdio> #include<string.h> #include<algorithm> using namespace std; const int M1 = 555; const int INF = 111111111; int N,K; int ans; int w[M1][M1];//w[i][j] is the number of white horses in the last stable when the first i horses were placed in 1st j stables with minimum unhappiness int b[M1][M1];//b[i][j] is the number of black horses in the last stable when the first i horses were placed in 1st j stables with minimum unhappiness int f[M1][M1];//f[i][j] means the minimum unhappiness when the first i horses were placed in 1st j stables //function: f[i][j] = min(f[i-1][j-1],f[i-1][j]+w[i-1][j] or b[i-1][j]); int main() { memset(w,0,sizeof(w)); memset(b,0,sizeof(b)); memset(f,0,sizeof(f)); scanf("%d%d",&N,&K); for(int i=0;i!=M1;++i) { for(int j=i+1;j!=M1;++j) f[i][j] = INF; f[i][0] = INF; } int tmp; scanf("%d",&tmp); if(tmp) ++b[1][1]; else ++w[1][1]; f[1][1] = 0; for(int i=2;i<=N;++i) { scanf("%d",&tmp); for(int j=1;j<=min(i,K);++j) { f[i][j] = f[i-1][j-1]; b[i][j] = 0; w[i][j] = 0; if(tmp) { ++b[i][j]; if(f[i-1][j]+w[i-1][j]<f[i][j]) { b[i][j] = b[i-1][j]+1; w[i][j] = w[i-1][j]; f[i][j] = f[i-1][j]+w[i-1][j]; } } else { ++w[i][j]; if(f[i-1][j]+b[i-1][j]<f[i][j]) { b[i][j] = b[i-1][j]; w[i][j] = w[i-1][j]+1; f[i][j] = f[i-1][j]+b[i-1][j]; } } } } ans = f[N][K]; printf("%d",ans); return 0; } I think I have precision problems, please inspect my code (CSharp) and give some hints: UPD: ok, I found some mistakes in my algorithm. Edited by author 08.01.2013 14:49 OK, I got AC, but I have question to admins: Is there test with n = 1000, m = 1000? My solution on my PC works more than 0.5 secs with such test. try to solve this with dp. my solution with dp( O(n*m) ) works on my pc only 0m0.016s if n=m=1000 :) Test: 3 3 +.+-+.+ |1|2| | +-+.+.+ | | . | +-+.+.+ | | | | +-+.+.+ Answer: 8 Just look( in back order ): +.+-+.+ | | | | +-+.+.+ | | . | +-+.+.+ | | | | +-+.+.+ 0 0
+.+-+.+ | | | | +-+.+.+ | | . | +-+.+.+ | | |0| +-+.+.+ 0
+.+-+.+ | | | | +-+.+.+ | | . | +-+.+.+ | |0|0| +-+.+.+
+.+-+.+ | | | | +-+.+.+ | | .0| +-+.+.+ | |0| | +-+.+.+
+.+-+.+ | | | | +-+.+.+ | |0.0| +-+.+.+ | | | | +-+.+.+
+.+-+.+ | |0| | +-+.+.+ | | .0| +-+.+.+ | | | | +-+.+.+
+.+-+.+ | |0|0| +-+.+.+ | | . | +-+.+.+ | | | | +-+.+.+
0 +.+-+.+ | |0| | +-+.+.+ | | . | +-+.+.+ | | | | +-+.+.+
0 +.+-+.+ | |0| | +-+.+.+ | | . | +-+.+.+ | | | | +-+.+.+
0 +.+-+.+ | |0| | +-+.+.+ | | . | +-+.+.+ | | | | +-+.+.+
+.+-+.+ |0|0| | +-+.+.+ | | . | +-+.+.+ | | | | +-+.+.+
Hi, I am just beginning to write code although i am bit familiar with algorithms and datastructures. I wrote this solution. But its wrong. I kinda feel that i am overcounting but not sure where it is. if( n == 0) return 1; if(n == 1) return k-1; return k-1 * ( k * f(n-2,k) + k * k-1 * f(n-3,k) ) if digit n-1 can have zero there are k ways we can fill it, hence k * f(n-2,k) else if digit n-1 cannot have zero then we can use k-1 ways for digit n-1 and k ways for n-2. Edited by author 14.01.2013 18:41 #include <stdio.h> #include <math.h> int ax,ay,bx,by,cx,cy,l; double AB,AC,BC,p,h,mas[3],tmp; int main(){ scanf("%d%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy,&l); AC=sqrt(pow(ax-cx,2.0)+pow(ay-cy,2.0)); AB=sqrt(pow(ax-bx,2.0)+pow(ay-by,2.0)); BC=sqrt(pow(bx-cx,2.0)+pow(by-cy,2.0)); p=(AB+BC+AC)/2; h=((sqrt(p*(p-AB)*(p-BC)*(p-AC))*2)/AB)-l; AC=AC-l; BC=BC-l; if(AC<0) AC=0; if(BC<0) BC=0; if(h<0) h=0; mas[0]=AC; mas[1]=BC; mas[2]=h; for(int i=0;i<3;i++){ for(int j=i+1;j<3;j++){ if(mas[i]>mas[j]){ tmp=mas[i]; mas[i]=mas[j]; mas[j]=tmp; } } } if(((ax!=bx) && (ay!=by) || (0-ax!=bx) && (0-ay!=by)) && (ax<cx && bx>cx) || (ax>cx && bx<cx) || (ay<cy && by>cy) || (ay<cy && by>cy)) printf("%.2f\n%.2f",mas[0],mas[2]); else { if(BC<AC) { tmp=AC; AC=BC; BC=tmp; } printf("%.2f\n%.2f",AC,BC); } } My solution is a BFS using deque, but i am gettign WA 4. Please Help me someone... Edited by author 13.01.2013 19:42 Edited by author 13.01.2013 19:42 UPD: At last I got AC, there was just a really stupid bug. Wrong output is replaced with correct one produced by my AC solution. Please, anybody who has AC solution, check my solution's answer for this big random test: INPUT 50 50 GRYBYYWWRYBBGRGGBRRGGYRWRRGGWBRGGWYRRYBYWGRWWYGGWW RYRRRYWGYWGBBRWGBRYWGBBYBBGGWWYWYYGBGGGWYYGWRWWRYG WBYWYBRGWGGBYRBYRWRRGBGGBRBYGRBBGYGBRGRRRRWWBYYWGW RGGBWWBGRBBYYRWWBGRBGGYBGGWYWYGYWYWWBWRRWWWWRGBRWY YGBGBYYGWWYWYYYRBBWWWRYWWBWWBGWGYWYRRRWRWYBRWGBWGG RYRBWGRGBWYRYGGWRGGYRGRYBRBBWYGWGYBWRBRBWGRRRRYYGY GYWRBBYYGRBBWWYWYGRYYRGYWBRGGBWRBYYGGGGWWBBWRWRBWG GWGRGYGRYGBBWGYYRYWYYBBYG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WWRWWRWBGYWRWYWYRYGYBWYGYWW GYGYBRGWYGWWWYRRWYBGYBRWYYYBGWYWYYRBWYBGYWGRBBGBGG OUTPUT B: 43900 G: 47932 R: 26046 W: 38176 Y: 21310 Am I correct? Edited by author 14.02.2012 18:03 Edited by author 14.02.2012 18:03 3 3 WYY YWR WYR answer: R: 4 W: 12 Y: 8 I am good man! In promlem it is said that: "05 If there is a figure of the main color:" But I have wrote in my program: "WHILE there is a figure of the main color:" Stupid bug! =) Edited by author 13.01.2013 19:05 Ioannis Hikari Test # 13 янв 2013 16:34 What does the number under column Test # mean? can anybody explain to me why f[0]=1????....i mean it's logically wrong....but the algo is giving AC with these assumption.... It's NOT logically wrong. Learn more math and then you'll understand it. Yes. > Yes. You asked if "No solution" is impossible. My answer was yes. So I'm saying that such a test doesn't exist. Thanks! it was matter of bad English for such an Iranian Boy... Can you help me a little bit more? which algorithm i should use? DFS and BFS dont help... Brute Force doesn`t seem beauty ;)! Please Help Me Best Aidin_n7@hotmail.com First put every child into the first team. Then while there exists a child who has more than one opponent in his team, just move him to the other team. > I don't know how. Could you explain it for me? Thank you very much! Can you give me a code, plz? The idea really works. But did you prove that this algo is correct? (Why will it finish the work in a finite number of steps?) It works because in each step number of edges between the two parts increases and obviously it can't be more than E. This proof incomplete and doesn't shed light to the point. We should add next: if person Q on the left side have >=2 enemy on the left then he don't have more than 1 enemies in persons on the right because in other case he would have >=4 enemies. Edited by author 26.11.2011 08:42 It is clear that if proposed algorithm terminates then we have found a solution. But does it allways terminate? I will try to add my 5 cents by giving a short yet complete proof of termination. Let us first introduce the decreasing measure M. We define M to be equal to the number of edges of the graph on the same(!) side. Algorithm terminates if measure decreases with each iteration of algorithm. Let us consider 3 possible situations: 1) We change side of a child with 3 enemies on his side. Then M decreases by 3. 2a) We change side of a child with 2 enemies on his side and 0 enemies on other side. Then measure decreases by 2. 2b) We change side of a child with 2 enemies on his side and 1 enemy on other side. Then M decreases by 2 and increases by 1. 3) If child has only one enemy on his side, then we do nothing. According to described cases M will decrease after each iteration. Hence, algorithm terminates. Hope this helps :) Edited by author 27.03.2006 01:16 here is my code. please help me :(( #include <stdio.h> #define HMAX (1<<17) int N; unsigned int H[HMAX]; void sift(int x) { int aux, up = x>>1; if (x < 1) return; if (H[x] > H[up]) { aux = H[x]; H[x] = H[up]; H[up] = aux; sift(up); } } void perc(int x, int n) { int l = x<<1, r = (x<<1)+1, max, aux; if (r > n) return; max = l; if (H[l] < H[r]) max = r; if (H[max] > H[x]) { aux = H[max]; H[max] = H[x]; H[x] = aux; perc(max, 1+N/2); } } int main() { int i, val; long double sol; unsigned int last, blast; // freopen("1306.in", "r", stdin); scanf("%d", &N); H[0] = 4294967295; for (i = 1; i <= 1+(N/2); i++) scanf("%lu", H+i); for (i = 1; i <= 1+(N/2); i++) sift(i); for (i = 2+(N/2); i <= N; i++) { scanf("%d", &val); if (val < H[1]) { H[1] = val; perc(1, 1+(N/2)); } } blast = H[1]; H[1] = 0; perc(1, (N/2)); last = H[1]; sol = last*0.5; sol += blast*0.5; if ( (N&1) == 0 ) printf("%0.1llf\n", sol); else printf("%u\n", blast); return 0;
} please help me Try test with n=2. FE 2 10 20 The result of my Program is 15.0 How about you ?? In my opinion, test #2 contain data like this: 1 5 Correct answer is: 5.0 I had a problem with output format. We should output the answer with one decimal digit after decimal point. My wrong program had written: 5 without fractional part. |
|