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!
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 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!
Name |
---|
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.