2015年1月28日 星期三

2015/01/28 Codeforces 492D. Vanya and Computer Game

// http://codeforces.com/contest/492/problem/D
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

int gcd(int a, int b)
{
    while( a && b )
    {
        if( a < b ) swap(a, b);
        a %= b;
    }

    return a+b;
}

int N;
int x, y;

ll lcm;

int Ans[10000000];

int main()
{
    scanf("%d", &N);

    scanf("%d %d", &x, &y);

    lcm = (ll)x*y/gcd(x, y);

    ll nx = 0, ny = 0; int now = 0;

    Ans[0] = 0;

    while( nx < lcm && ny < lcm )
    {
        if( nx+x == ny+y )
        {
            Ans[++now] = 0;
            Ans[++now] = 0;

            nx += x;
            ny += y;
        }
        else if( nx+x < ny+y )
        {
            Ans[++now] = 1;
            nx += x;
        }
        else
        {
            Ans[++now] = 2;
            ny += y;
        }
    }

    for(int Ni = 0; Ni < N; Ni++)
    {
        int a;
        scanf("%d", &a);

        a %= now;

        if( Ans[a] == 0 ) puts("Both");
        else if( Ans[a] == 1 ) puts("Vova");
        else puts("Vanya");
    }
}

沒有留言:

張貼留言