StellarSpecter's blog

By StellarSpecter, history, 3 days ago, In English

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!

  • Vote: I like it
  • -6
  • Vote: I do not like it

»
3 days ago, # |
  Vote: I like it -9 Vote: I do not like it

It's the simplest. Just run loops EASY PEASY

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

The $$$x$$$ never moves. You can always reach it in a finite number of moves. Only the $$$y$$$ does.

»
3 days ago, # |
  Vote: I like it +4 Vote: I do not like it

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.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

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.