ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1011. Conductors

To admins
Posted by JIeHuH*CCCP 29 Oct 2006 17:45
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?
Posted by JIeHuH*CCCP 15 Nov 2006 04:29
Re: Could admins give answer to me?
Posted by Nechaev Ilya (Rybinsk SAAT) 15 Nov 2006 11:42
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?
Posted by JIeHuH*CCCP 20 Nov 2006 09:00
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
Posted by Nechaev Ilya (Rybinsk SAAT) 20 Nov 2006 17:24
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..."
Posted by JIeHuH*CCCP 21 Nov 2006 04:48
Nechaev Ilya (Rybinsk SAAT) wrote 20 November 2006 17:24

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:49
Re: To admins
Posted by Daniel Ampuero 5 Dec 2006 21:22
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...)