|
|
back to boardWhat's wrong with test 22? In test 22 P=Q Suppose down=P*100 & up==Q*100 then the answer should be: if(down==up){ for(b2=1;b2<10000;b2++) { if(up*b2%10000==0) break; } printf("%d\n",b2); return 0; } but this doesn't work... So I believe that there must be sth wrong.Please check it! Re: P < Q Posted by xj.ammo 10 Dec 2005 09:55 Then I don't believe that it satisfies the two digits precision. When I changed down=P*100 to down=P*1000 my prog got accepted. Re: P < Q I also had failed at the test case 22 due to Time Limit Exceeded; after I had seen this thread I changed my program from P*100 to P*1000 as xj.ammo did, I got Accepted too, and it means when I considered three digits after decimal instead of two, then P<Q in that case(because when P<Q, the only loop in my program will terminate within 100000(or 100001, I'm not sure) iterations, which is very quick in computers nowadays). Does it means the judge had the test case 22 precised down to three digits and in that case P and Q only differ in the third digit after decimal point? Re: What's wrong with test 22? Let me explain you the trick with the test #22. When you have for example P = 30.55, then if you look at it in the Debugger you wiil see that it is represented as 30.549999 . So when you take only 2 decimal digits you will get 30.54 (which is incorrect). And if you take 3 digits you will have 30.549 and it will work. P. S.: If P = 40.79 than for real you have 40.790001 . Re: What's wrong with test 22? Why don't you just use round()? Part of my AC program: read(pe,qe); p:=round(pe*100); q:=round(qe*100); Re: What's wrong with test 22? on C/C++ there is NOT a function double round (double) in math.h (I don't know why - it is in the standart), so you can use an epsilon for this purpose (you'll get an error only if pe == x.9999 which will be trunkated to x instead of x+1 => so just add 1e-9) p = (int)(pe * 100 + 1e-9) q = (int)(qe * 100 + 1e-9) Re: What's wrong with test 22? Posted by scythe 17 Jan 2012 01:54 Great tip from Ostap Korkuna (LNU). use int or long long in your calculations + that tip = ACCEPTED |
|
|