CodeForces 69D Dot (博弈+記憶化)

來源:互聯網
上載者:User

標籤:des   style   os   io   for   ar   問題   div   

Description

Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:

  • On the checkered paper a coordinate system is drawn. A dot is initially put in the position(x,?y).
  • A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the liney?=?x.
  • Anton and Dasha take turns. Anton goes first.
  • The player after whose move the distance from the dot to the coordinates‘ origin exceedsd, loses.

Help them to determine the winner.

Input

The first line of the input file contains 4 integers x,y, n,d (?-?200?≤?x,?y?≤?200,?1?≤?d?≤?200,?1?≤?n?≤?20) — the initial coordinates of the dot, the distanced and the number of vectors. It is guaranteed that the initial dot is at the distance less thand from the origin of the coordinates. The followingn lines each contain two non-negative numbersxi andyi (0?≤?xi,?yi?≤?200) — the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.

Output

You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.

Sample Input

Input
0 0 2 31 11 2
Output
Anton
Input
0 0 2 41 11 2
Output
Dasha

題意:有一個移點的遊戲,Anton先移,有n個移動選擇,也可以沿著直線y=x對稱且只能一次,如果有人先移動到距離原點>=d的時候為輸

思路:對於直線y=x對稱的情況,沒有考慮,因為如果有人下一步一定移到>=d的位置的話,那對稱是解決不了問題的,所以我們不考慮,現在設dfs(x, y)表示當前移動人是否能贏,一旦有必贏的情況就返回贏

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 500;int n, d;int dx[maxn], dy[maxn];int vis[maxn][maxn];int dfs(int x, int y) {if ((x-200)*(x-200) + (y-200)*(y-200) >= d*d)return 1;if (vis[x][y] != -1)return vis[x][y];for (int i = 0; i < n; i++)if (dfs(x+dx[i], y+dy[i]) == 0)return vis[x][y] = 1;return vis[x][y] = 0;}int main() {int x, y;scanf("%d%d%d%d", &x, &y, &n, &d);x += 200, y += 200;for (int i = 0; i < n; i++) scanf("%d%d", &dx[i], &dy[i]);memset(vis, -1, sizeof(vis));if (dfs(x, y)) printf("Anton\n");else printf("Dasha\n");return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.