I solved it as if y<0 and abs(y) >= abs(x) cout<<"NO"<<endl;
But this did not work even after trying so long.
why is this incorrect can anyone help this newbie?
THANKS!
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
I solved it as if y<0 and abs(y) >= abs(x) cout<<"NO"<<endl;
But this did not work even after trying so long.
why is this incorrect can anyone help this newbie?
THANKS!
Название |
---|
It's the simplest. Just run loops EASY PEASY
The $$$x$$$ never moves. You can always reach it in a finite number of moves. Only the $$$y$$$ does.
If y = -1, you move first and can therefor still reach it, as you'll be at -1 before it moves. You can move diagonally, so as long as y is greater than -1 you can reach it. Since regardless of the X, you can still move downwards at the same time as going to some side.
The basic idea is this: As x remains unchanged for the point under discussion: We try to reach x, and just to offset the fall, just assume we also go down every second. So, we move (1 right + 1 down) or (1 left + 1 down) depending on x. Now, after abs(x) moves, we reach x with y coordinate -abs(x). By this time, the coin is at y-coordinate: y_initial — abs(x) + 1. So, if the y-coordinate of the coin is above that of ours, we are through! Else, not. Note that this won't give the minimum moves, but just tells whether the situation is feasible or not.