CodeForces 492D Vanya and Computer Game (思维题)

D. Vanya and Computer Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai hits.

Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.

Input

The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.

Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.

Output

Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.

Sample test(s)
input
4 3 2
1
2
3
4
output
Vanya
Vova
Vanya
Both
input
2 1 1
1
2
output
Both
Both
Note

In the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.

In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.

 

思路: 首先找出循环节,循环节的次数就是 x/=gcd(x,y), y/=gcd(x,y) , 然后对于 a, a要跟x+y取余,如果a==0 或者 a==x+y-1就代表同时杀死。否则就模拟一遍,第几步攻击的是谁。

注意,要用longlong

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
//const int INF = 1e9;
const double eps = 1e-6;
const int N = 3*1000000;
ll cas = 1;

char s[][10]={"Vanya","Vova","Both"};
int who[N];
ll n,x,y;

ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}

void run()
{
    ll g = gcd(x,y);
    x /= g;
    y /= g;
    ll xy = x+y;
    swap(x,y);
    ll xx = x, yy = y;
    for(ll i = 1; i<=xy ; i++)
    {
        if(xx < yy)
        {
            who[i] = 0;
            xx += x;
        }
        else
        {
            who[i] = 1;
            yy += y;
        }
    }
    ll a;
    for(ll i = 1; i <= n; i ++ )
    {
        scanf("%I64d",&a);
        a %= xy;
        if(a==0 || a==xy-1)
            puts(s[2]);
        else
            puts(s[who[a]]);
    }
}

int main()
{
    #ifdef LOCAL
    freopen("case.txt","r",stdin);
    #endif
    while(scanf("%I64d%I64d%I64d",&n,&x,&y)!=EOF)
        run();
    return 0;
}

 

转载于:https://www.cnblogs.com/someblue/p/4136435.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值