In the latest contest, i got trouble in problem H.
When i want to compare x is lager than y, i use x>y+eps (i learn this from a book), but i get WRONG ANWSER , but when i just use x>y ,then i accept .
I just wonder which one is true. Thx first.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
In the latest contest, i got trouble in problem H.
When i want to compare x is lager than y, i use x>y+eps (i learn this from a book), but i get WRONG ANWSER , but when i just use x>y ,then i accept .
I just wonder which one is true. Thx first.
Name |
---|
In my experience, I've only seen epsilons used when comparing for equality, not for greater-than or less-than.
I can see where the y + ε comes from — we consider x and y to be equal if they are within ε of each other, so it makes sense that for a "strictly greater than" operation we would rule that out — but I think we can make a safe assumption that a greater-than or less-than relationship is, unlike equality, preserved in floating-point operations, if you're not going to the limit of the number's precision boundary. This is relevant.
(Anyone please feel free to prove this incorrect if you have a counterexample.)
i think you use a large eps, try smaller one
try 1e-15 for example
Contrary to popular belief that you always need to use eps when working with floating point numbers, there are some situations when eps is not needed and it may decrease the precision. If it was like that then it would be builtin. Keep in mind that floating points are deterministic and they perform operations correctly within limits of their precision, and performing operation with the same arguments twice will give exactly the same result. I will give some examples:
When possible try to think of what problem are you trying solve by using eps and choose appropriately. It depends on the task if it is worse to have false positives or false negatives.
Thanks for your detail explanation. :-p