On my PC this code outputs 1 9 3 for test№15. But in codeforce another output Here is my submition: http://codeforces.me/contest/618/submission/15669012 I think this is because of doubles, but I'm not sure. Could smb point my mistake, please?
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
On my PC this code outputs 1 9 3 for test№15. But in codeforce another output Here is my submition: http://codeforces.me/contest/618/submission/15669012 I think this is because of doubles, but I'm not sure. Could smb point my mistake, please?
Название |
---|
Need sort with struct, like this
Never ever use Heron's formula for calculating triangle's area in competitive programming. I have not heard about a single occurence when it can be useful. Especially do not use it if the resulting area can be small (say, zero). Heron's formula is very sensitive to precision in that matter, and
long double
s probably won't help you there. Say, when c = 2a = 2b, semi-circumference is equal to c = 2a, then formula becomes p(p - a)(p - b)(p - c) ≈ 2a·(2a - a)·(2a - 2a)·(2a - 2a) ≈ 4a3(a - a), and even a small precision error (like 10 - 11) in the last factor leads to huge error in the total because of the big factor in the beginning.So, yes, it's precision error. Your program genuinely thinks that that triangle is non-degenerate.
Use cross product instead: area of triangle (0, 0) – (x1, y1) – (x2, y2) is |x1y2 - x2y1|. There is only one subtraction (and that's the bad guy who spoils precision the most) and you do not multiply that error by another factors.
Got it. Thanks a lot!