zoukankan      html  css  js  c++  java
  • Codeforces 69D. Dot 博弈 dp

    D. Dot
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 line y = x.

  • Anton and Dasha take turns. Anton goes first.

  • The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses.

    Help them to determine the winner.

Input

The first line of the input file contains 4 integers xynd ( - 200 ≤ x, y ≤ 200, 1 ≤ d ≤ 200, 1 ≤ n ≤ 20) — the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (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 test(s)
input
0 0 2 3
1 1
1 2
output
Anton
input
0 0 2 4
1 1
1 2
output
Dasha
Note

In the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line y = x. Dasha will respond to it with the same move and return the dot in position (2;3).


-----------------------------------

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;
}







查看全文
  • 相关阅读:
    github上Devstack的一些变动,截至8.20
    Tokyo Tyrant(TTServer)系列(二)-启动參数和配置
    云方案术语
    四大桌面云显示协议解析
    rdesktop -u qinrui -p 'Aa7788..' 192.168.3.117 -a 32 -g workarea
    IOS开发之block应用
    怎样用EA设计ER图
    使用Jsoup解析和操作HTML
    Speak a Good Word for SB
    LeetCode234_PalindromeLinkedList (推断是否为回文链表) Java题解
  • 原文地址:https://www.cnblogs.com/cyendra/p/3038418.html
  • Copyright © 2011-2022 走看看