# [Codeforces492D] Vanya and Computer Game

## 描述 Description

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.

## 输入格式 InputFormat

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.

## 输出格式 OutputFormat

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.

7 5 20
26
27
28
29
30
31
32

Vova
Vova
Vova
Both
Both
Vova
Vova

Codeforces 492D

## 代码 Code

``````#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxm=2000005;
int i,j,t,n,m,l,r,k,z,y,x;
int f[maxm];
int main()
{
scanf("%d%d%d",&n,&x,&y);
l=r=0;
i=0;
while (l<=x || r<=y)
{
if ((double)(l+1)/x>(double)(r+1)/y)
{
f[i++]=1;
r++;
}
else if ((double)(l+1)/x<(double)(r+1)/y)
{
f[i++]=0;
l++;
}
else
{
f[i++]=2;
f[i++]=2;
l++;r++;
}
}
for (i=1;i<=n;i++)
{
scanf("%d",&m);
m=(m-1)%(x+y);
if (f[m]==0) printf("Vanya\n");
if (f[m]==1) printf("Vova\n");
if (f[m]==2) printf("Both\n");
}
return 0;
}``````