Hey guys! It's my first time here, so sorry if I don't know the rules too much. Please correct me for any errors. My problem is as follows. Given a coordinate on a grid, and starting at the origin, for each nth step, the man covers 2^n-1 units of ground in any of the four possible directions. How can we determine whether or not a point is reachable from the origin, and how to do it in the least number of steps if it is?
I'm thinking of using maybe greedy? But that would not work well as it might not be able to accurately determine the impossibility of reaching the point. Also, the greedy solution may not accurately detect impossibility and wave a possible coordinate off as impossible.
Is recursing through all the possible routes right? The maximum x and y coordinates are 10^9, so I don't know how it would run in time. I'm not quite sure how to start...
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int x, y, M;
cout << "Input x y: "; cin >> x >> y;
M = abs( x ) + abs( y );
if ( M % 2 == 0 )
{
cout << "Impossible";
}
else
{
int n = 1;
for ( int p2 = 2; p2 <= M; p2 *= 2 ) n++;
cout << "Requires " << n << " steps\n";
}
}