Общий форумI dont understand: when I had swaped 'Impossible' to '0' my program solved more tests than late. there is no test where the answer is impossible, you can can make every mark you want Even below 1.0 or above 10.0? I also do not see under what conditions it can be "impossible". Even if y = 1.0, then this is the result of rounding, but the ratio of the sum of estimates to their number, equal to 1.0499, really approaches. void fallBack(int angle, int M, int curEnergy, int curAmmo); void advance(int angle, int M, int curEnergy, int curAmmo); int findX(int curEnergy); int main() { int curEnergy, curAmmo; char behaviour; int M, MP, angle; int N, NP, offset; scanf_s("%i %i", &curEnergy, &curAmmo); scanf_s(" %c", &behaviour); scanf_s("%i %i %i", &M, &MP, &angle); if (behaviour == 'A') { scanf_s("%i %i", &N, &NP); } else if (behaviour == 'P') { scanf_s("%i", &offset); offset *= -1; } while (1) { switch (behaviour) { case 'A': if ((N*NP) > (M*MP * 3)) { advance(angle, M, curEnergy, curAmmo); return 0; } else { fallBack(angle, M, curEnergy, curAmmo); return 0; } case 'D': if ((M * 20) >= curAmmo) { fallBack(angle, M, curEnergy, curAmmo); return 0; } else { behaviour = 'G'; break; } case 'G': if (M == 0) { printf("STOP"); } if (abs(angle) < 5) { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); return 0; } else if (angle >= 5) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (angle <= -5) {
printf("RIGHT %i", findX(curEnergy)); return 0; } case 'P': if (M != 0) { behaviour = 'D'; break; } else { if (offset >= -180 && offset <= -160) { printf("BACKWARD %i", findX(curEnergy)); return 0; } else if (offset > -160 && offset < -90) { printf("RIGHT %i", findX(curEnergy)); return 0; } else if (offset >= -90 && offset < -20) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (offset >= -20 && offset <= 20) { printf("FRONT %i", findX(curEnergy)); return 0; } else if (offset > 20 && offset <= 90) { printf("RIGHT %i", findX(curEnergy)); return 0; } else if (offset > 90 && offset < 160) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (offset >= 160 && offset <= 180) { printf("BACKWARD %i", findX(curEnergy)); return 0; } } } } return 0; } void fallBack(int angle, int M, int curEnergy, int curAmmo) { if (abs(angle) >= 5 || M == 0) { printf("BACKWARD %i", findX(curEnergy)); } else { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); } } void advance(int angle, int M, int curEnergy, int curAmmo) { if (abs(angle) >= 10 || M == 0) { printf("FRONT %i", findX(curEnergy)); } else { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); } } int findX(int curEnergy) { int X; if (curEnergy > 100) { X = 100; } else { X = curEnergy; } return X; } Event simple A+B get's around 900KB for me, but I've seen some ACs with 400KB in Java 1.8. Can you tell me how? is it doing search in O(1) for each pair of nodes? Write code that way: if(n>=1000) puts("legion"); else if (n>=500) puts("zounds"); else if (n>=250) puts("swarm"); else if (n>=100) puts("throng"); else if (n>=50) puts("horde"); else if (n>=20) puts("lots"); else if (n>=10) puts("pack"); else if (n>=5) puts("several"); else puts("few"); use printf and scanf instead of cin,cout; Thank you! Very useful hint with cin,cout my programm get TLE on test 21 Or use cin.sync_with_stdio(false); sync doesn't help. scanf_s/printf got me through time limit. PS unordered_map gives little speed boost too. Edited by author 11.06.2014 12:31 ios_base::sync_with_stdio(false); cin.tie(0); with map 0.249s.with unorderd_map 0.171s. a=[] for i in range(int(input())): c=str(input()) if len(a)==0 : a.append(c) continue d=(a[0].split())[1] d=int(d) k=int((c.split())[1]) if k>=d : a.reverse() a.append(c) a.reverse() else: for j in range (len(a)): h=int((a[j].split())[1]) if k >= h: p = a[:j] o = a[j:] p.append(c) p.extend(o) for i in range(len(a)): print(a[i]) Edited by author 26.09.2018 20:38 the number of integer point inside circle is sigma(r*r/(4*i+1)-r*r/(4*i+3)) use stern borcot to cut hyperbola curve it can be done O(r^(2/3)) what do you mean by cut huperbola curve? maybe we can directly use stern borcot tree to cut circle I think it is faster... basic idea is use line segment (x1,y1) --->(x2,y2) with slope -a/b(a>0,b>0) to cut quadric curve so that all of integer point strictly under this line segment is inside the quadric curve (x1,y1) and (x2,y2) is strictly outside the curve if we know (x1,y1),(x2,y2) and -a/b we can find next -(a1/b1) a/b and a1/b1 is neibour in stern borcot tree .it can be proved there are O(n^1/3) state if the quadric curve is huperbola curve x*y==n My solution convert this problem to compute simga(r*r/(4*i+1)-r*r/(4*i+3)) so it is huperbola curve (4*x+1)*y==r*r and (4*x+3)*y==r*r I have done twice ,so it is slow, dirctly cut circle only do once... Edited by author 25.09.2018 21:34 Edited by author 25.09.2018 21:37 will try that for sure, I don't see any way I can speed up my current solutoin, I only need to calculate squares n-(n/sqrt(2)) times, and I do only +/- operations per iteration(no sqrt and multiplication/divisions). and for any n, it runs 0.75-0.8 sec on my pc, but I still get TLE18 here. your computer is too strong, ural oj O(1e9) can't fit into 2 sec Edited by author 26.09.2018 20:03 int main() { optimize(); int n,k; cin>>n>>k; k--; int z=k; bool b=0; int a[n+10]; for(int i=0;i<n;i++) { if(k!=0) { if(b==0) { a[i]=k; b=1; z--; } else { if(z==0) { a[i]=0; k=0; b=1; continue; } a[i]=-k; k--; b=0; z--; if(z==0) k=0; } } else a[i]=0; //dbg(z); } for(int i=n-1;i>=0;i--) cout<<a[i]<<" "; //return main(); } when going to print 0 0 -3 3 or -3 3 0 0 I am getting WA..But When I print 0 0 -1 1 I get AC..Why?what is the difference between 1st two case and last one??Can anyone explain me?? Thanks to Oleksandr Kulkov for preparing! Thanks I almost have no problem to do on ural why is k =10 and n =2 output =90 #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { unsigned long long k[4]; for(int i=0;i<4;i++){ scanf("%llu",&k[i]); } printf("\n"); printf("%.4f\n",sqrt(k[3])); printf("%.4f\n",sqrt(k[2])); printf("%.4f\n",sqrt(k[1])); printf("%.4f\n",sqrt(k[0])); return 0; } Ошибка на тесте 2 /Error in test 2 Edited by author 09.09.2018 15:45 Во входном потоке может быть любое количество чисел, а не только четыре. Почините алгоритм проверки! Не контачит на сях. Вот код: #include <stdio.h> int main(int argc, char const *argv[]) { int a, b; a=1, b=5; printf("%i\n", a+b); return 0; } а с чего ты взял что вводимые данные будут целочисленные? В этом коде не считываются a и b из входного потока. Edited by author 23.09.2018 18:34 Hello, everyone. Just wanted to summarize some info about this problem. Ok, my code got AC with following things in it: 1. My pi was 3.1415926535897932384626433 (perhaps it is enough) 2. I used this formula from wikipedia deltaArc=acos(sin(phiA)*sin(phiB)+cos(phiA)*cos(phiB)*cos(deltaL)); distance = deltaArc*3437.5; (see the first formula from wikipedia http://en.wikipedia.org/wiki/Great-circle_distance)3. I used the following condition: if(100.00-distance>0.005) printf("DANGER!\n"); Hope it will help somebody. thanks a lot ...your formula is really useful.^_^ Used everynth what is written here. However still WA8. Any new ideas?... Do u know that pi can be calculated by this formula: atan(1) * 4? 1)Solution always exists and his complexity <= O(n^2) 2)Try to solve the problem when the permutation is n (n-1) ... (n-left+1) 1 2 3 ... right where left+right=n. After O(n^2) steps you can get n 1 2 3 ... (n-1). Then after O(n^2) steps you can get 1 2 3 ... n. 3)Try to reduce the problem to this permutation by O(n^2) steps. 4)Good to know: 1 2 3 ... t x-> 2 1 3 ... t x -> 3 1 2 4 ... t x -> 4 1 2 3 5 ... t x ->... -> t 1 2 3 ... (t-1) x -> x 1 2 3 ... t by t steps. I call this operation "Shift(t)". Edited by author 26.07.2018 20:20 simplest solution: i=0..n-1 : while p[i] <> n do change(p[i]); Edited by author 22.09.2018 14:02 |
|