|
|
back to boardTo admins Dear admins, Please pay attention to my message. Problem 1011. Are you sure with the test 17. My solution with the formula a: =-1; repeat inc (a); until (trunc (a*q-0.00000001)-trunc (a*p))> 0; was WA at test #17, though I sure that it's true. After a chat reading I have corrected it a: =-1; repeat inc (a); until (trunc (a*q-0.0000000000000001)-trunc (a*p+0.0000000000000001))> 0; , and it was AC, though I am sure, that it's wrong in math. 1) ------|p*a|-(k)-------------|q*a|------------(k+1)------- p*a - [p*a] = 0.9999999999... {0. (9)} and [q*a-0] - [p*a] = 1 (> =1) 2) 0 = 0.000000000001 p*a + 0 - [p*a + 0] = 0 (become integer) and [q*a-0] - [p*a+0] = 0 PS: or it is just an Pascal accuracy error? Edited by author 15.11.2006 04:27 Could admins give answer to me? Re: Could admins give answer to me? Try make solution that uses olny integers (except variables for reading input). So you will have no problems with precision. I got only WA's while using floating point ariphmetic (in C++ and Pascal), and AC while using integers. Edited by author 15.11.2006 11:45 Re: Could admins give answer to me? So "a" is integer (you cannot use inc with real) "trunc (a*q-0.00000001)" and "trunc (a*p)" are int too Re: To admins You don't understand me. Use something like this for reading input: double p1, q1; int p, q; .............. scanf("%lf%lf", &p1, &q1); p = floor(p1*100+0.5); q = floor(q1*100+0.5); And in your solution don't use p1, q1, and any other floating point variables and operations at all. Edited by author 20.11.2006 17:26 Re: "...don't use p1, q1, and any other floating point variables..." p = floor(p1*100+0.5); q = floor(q1*100+0.5); why are you using +0.5 with p1 and q1??? IMHO it's not fare and it's false. Edited by author 21.11.2006 04:49Re: To admins You could also do the follow thing: int p, q; scanf("%d.%d", &p, &q); where p is the integer part of the number and q is the rational part of the number. (sorry for the bad english...) |
|
|