This game is over, because except for a finite number (2) of reflections about the line y = x,the coordinates are changed to non-negative integer (and at least one coordinate is changed to a positive number).
Algorithm for solving this problem is DFS / BFS (states) where the state is a pair of coordinates, and two logical variables, which denote if the 1 (2) player had reflected a point about the line y = x.
Total number of states is obtained by S <= 4D^2 (pairs of coordinates) * 4 (Boolean variables).
Processing of one state takes O (N) actions (do not forget to try to reflect the point about the line y = x, if the player had not made it earlier in the game). Thereby, we have the overall asymptotic O (ND^2), which works on C + + in less than 200ms.
------------------------------------#include <iostream> #include <cstring> using namespace std; int n,d; int vx[30],vy[30]; int f[1111][1111]; int dfs(int x,int y) { int bx,by; bx=x+500; by=y+500; if (f[bx][by]!=-1) return f[bx][by]; if (x*x+y*y>=d*d) return 1; for (int i=1;i<=n;i++) { if (!dfs(x+vx[i],y+vy[i])) return f[bx][by]=1; } return f[bx][by]=0; } int main() { int x,y; memset(f,-1,sizeof(f)); cin>>x>>y>>n>>d; for (int i=1;i<=n;i++) { cin>>vx[i]>>vy[i]; } if (dfs(x,y)) { cout<<"Anton"<<endl; } else { cout<<"Dasha"<<endl; } return 0; }