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 1942. Attack at the Orbit

Fractional part detection
Posted by bsu.mmf.team 5 Jan 2013 20:18
I used this code:
double x, y; cin >> x >> y;
x *= 1000; y *= 1000;
int X = (int)x, Y = (int)y;

But this code doesn't work properly. For example, if x = -1.001, then X will be -1000 (in some cases one unit is lost).
How to avoid this in C++?
To solve this problem I had to read whole string and then parse it :)
Re: Fractional part detection
Posted by Vas 6 Jan 2013 00:58
My method got AC:
        cin >> a;
        A = (int)(a*1000.000001);
Re: Fractional part detection
Posted by Xel 10 Jan 2014 18:42
This task use some architectural float issues.
So we need minimize to use real numbers.

I try many times, but get AC only with manual parsing:

x,y = sys.stdin.readline().strip().split()
xs,ys = x.split('.'), y.split('.')
x = int(xs[1]), y = int(ys[1])
if xs[0][0]=='-': x=-x
if ys[0][0]=='-': y=-y


I use float number only one time - in last line, in sqrt.
Re: Fractional part detection
Posted by ASK 28 Mar 2014 21:54
I use (g++11)

 double a; scanf("%lf",&a);
 p[j] = (int(a*1000.000001) + 100000) % 1000;

"a*1000" gives WA

"cin >> a" gives TL45 even with "cin.sync_with_stdio(false)"