Codeforces 69D Dot(DFS)

6517 단어
Codeforces 69D Dot
링크:
제목.
“““ 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 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 x, y, n, d ( - 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 Input 0 0 2 3 1 1 1 2 Sample Output Anton
    Sample Input 0 0 2 4 1 1 1 2 Sample Output Dasha
    제목의 뜻
    초기 좌표와 극한 구역의 좌표를 정한 다음에 벡터를 주면 두 사람은 어떤 벡터를 선택해서 갈 수 있고 가장 먼저 극한 경계를 벗어나는 사람이 진다.누가 지냐고.
    분석하다.
    dfs 검색을 사용하면 현재 dfs의 값을 1로 되돌려줍니다.
    원본 코드
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<queue>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<cmath>
    #include<set>
    #include<map>
    #include<vector>
    #include<stack>
    #include<utility>
    #include<sstream>
    #define mem0(x) memset(x,0,sizeof x)
    #define mem1(x) memset(x,1,sizeof x)
    #define mem11(x) memset(x,-1,sizeof x)
    #define dbug cout<<"here"<<endl;
    //#define debug
    
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int INF = 0x7fffffff;
    const int MAXN = 1e6+10;
    const int MOD = 1000000007;
    
    struct Point{
        int x,y;
    };
    
    Point p[30];
    int f[1000][1000];
    int n,d;
    
    bool dfs(int x, int y){
        if(~f[x][y])
            return f[x][y];
        if((x-200)*(x-200) + (y-200)*(y-200) >= d*d)
            return 1;
        for(int i = 0; i < n; ++i)
            if(!dfs(x+p[i].x, y+p[i].y))
                return f[x][y]=1;
    
        return f[x][y]=0;
    }
    
    int main(){
        #ifdef debug
            freopen("C:\Users\asus-z\Desktop\input.txt","r",stdin);
            freopen("C:\Users\asus-z\Desktop\output.txt","w",stdout);
        #endif
        int x,y;
        cin >> x >> y >> n >> d;
        memset(f,-1,sizeof f);
        for(int i = 0; i < n; ++i){
            cin >> p[i].x >> p[i].y;
        }
        if(dfs(x+200,y+200))
            cout << "Anton" << endl;
        else
            cout << "Dasha" << endl;
        return 0;
    }
    

    좋은 웹페이지 즐겨찾기