数论 - Vanya and Computer Game

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 ≤ 1051 ≤ 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

 

Input
4 3 2
1
2
3
4

Output
Vanya
Vova
Vanya
Both

Input
2 1 1
1
2

Output
Both
Both

Hint

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.

 

 

--------------------------------------------------------------我是分割线^_^-------------------------------------------------------------------

 

 

题意:A,B俩人一起打怪,A一秒打X次,B一秒打Y次,(每个人的攻击是对所有的怪物都有效果),每个怪物被打ai下

就会死掉,问最后一下是谁打的。 

解法 :A打一次是1/X 秒 B打一次是1/Y秒,浮点数不好计算,我们把二者乘以XY,那么 A打一次就是Y秒,B打一次就是

X秒。然后二分怪物被打死的时间t.条件是t/X+t/Y>=a。

实际上是比例的问题,题意中A是1/x秒打一次,而B是1/y打一次,比例是1/x :1/y,可以两边都乘以xy,比例化为y:x,

意思是A打一次需要y秒,而B打一次需要x秒,注意乘以之后数据范围的变化,已经超过题目所给的1e9了,所以二分枚举

时间的时候要特别注意这一点= =。

 

 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std;

#define Int __int64
#define INF 0x3f3f3f3f

const int MAXN = 111111;
Int num[MAXN];
Int n, x, y;

bool Judge(Int mid, Int m) {
    Int s = mid / x + mid / y;
    if (s >= m) return true;
    else return false;
}
int main()
{
    //freopen("input.txt", "r", stdin);

    while (scanf("%I64d %I64d %I64d", &n, &x, &y) != EOF) {
        for (int i = 0; i < n; i++) {
            scanf("%I64d", &num[i]);
        }
        for (int i = 0; i < n; i++) {
            Int lower = 1, higher = 1e16;
            while (lower <= higher) {
                Int mid = (lower + higher) / 2;
                bool ok = Judge(mid, num[i]);
                if (ok) higher = mid - 1;
                else lower = mid + 1;
            }
            Int s = lower;
            if (s % x == 0 && s % y == 0) {
                printf("Both\n");
            } else if (s % x == 0) {
                printf("Vova\n");
            } else {
                printf("Vanya\n");
            }
        }
    }
    return 0;
}

 

posted @ 2016-08-10 14:11  苍鼠  阅读(182)  评论(0编辑  收藏  举报