Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

D. Vanya and Computer Game

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/492/problem/D

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.

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 Input

4 3 2
1
2
3
4

Sample Output

Vanya
Vova
Vanya
Both

HINT

 

题意

Vanya每秒钟可以砍x刀,Vova每秒可以砍y刀

有n次询问,给你一个怪兽的血量为ai,然后问你最后一刀是谁补的刀

同时补刀,输出Both

 

题解:

二分是多少s砍死这只怪兽

然后再check就好一下了~

代码

#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
    int n;
    long long x,y;
    scanf("%d%lld%lld",&n,&x,&y);
    for(int i=0;i<n;i++)
    {
        long long a;scanf("%lld",&a);
        long long l = 0,r = 1LL<<60;
        while(l<=r)
        {
            long long mid = (l+r)/2LL;
            if(mid/x+mid/y>=a)r=mid-1;
            else l=mid+1;
        }
        if(l%x==0&&l%y==0)printf("Both\n");
        else if(l%y==0)printf("Vanya\n");
        else printf("Vova\n");
    }
}

 

posted @ 2015-11-16 23:56  qscqesze  阅读(241)  评论(0编辑  收藏  举报