291B. Han Solo and Lazer Gunmysolution
I am using slopes concept in 2d geometry
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
291B. Han Solo and Lazer Gunmysolution
I am using slopes concept in 2d geometry
Name |
---|
Welcome to the wonderful world of floating-point numbers!
Can you explain me more clearly
Sorry, I wanted to write a little more, but then got distracted.
Basically floating point numbers are not precise. A computer can only hold a limited number of digits (here binary digits). E.g. executing the following C++ code gives
0.6666666865
.Therefore normally if you do some floating point arithmetik, then all your intermediate results will be slightly wrong, and you cannot compare values with
==
any more. E.g. the following code will assignb
with false, since for the computer0.3 * 3 + 0.1
will actually be slightly less than1
.If you want to compare two floating point values, you have to do it using a small epsilon.
Another thing. Always use
double
instead of float!Now to your code. I did some little testing, and actually this floating point problem might not actually be the case why your code doesn't work. Sorry. I guess I was a little bit to quick by judging your code.
Here's some small test case for you:
Your code returns
2
, although clearly all three points are on1
line. The reason is, that1/0
will give+infinity
, and-1/0
will give-infinity
. So you have to handle that case separately.