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.

Examples
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.

题意:va每秒可以打x次,vo每秒可以打y次,求第a[i]次是谁打的;

思路:循环节为x/gcd(x,y)+y/gcd(y,z);

   离线处理,最多2e6次左右,余数暴力;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
int ans[N];
struct is
{
int a;
int pos;
bool operator <(const is &b)const
{
return a<b.a;
}
}a[N];
int gcd(int x,int y)
{
return y==?x:gcd(y,x%y);
}
int main()
{
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
int len=x/gcd(x,y)+y/gcd(x,y);
for(int i=;i<=n;i++)
scanf("%d",&a[i].a),a[i].a%=len,a[i].pos=i;
sort(a+,a+n+);
int va=;
int vo=;
double xx=1.0/x;
double yy=1.0/y;
for(int i=;i<=n;i++)
{
while(va+vo<a[i].a)
{
if(va*xx+xx<vo*yy+yy)
va++;
else
vo++;
}
ans[a[i].pos]=(va*xx-vo*yy>eps?:-);
if(a[i].a==len-||a[i].a==)ans[a[i].pos]=;
}
for(int i=;i<=n;i++)
if(ans[i]==)
printf("Vanya\n");
else if(ans[i]==)
printf("Both\n");
else
printf("Vova\n");
return ;
}

最新文章

  1. Spring Boot中的事务管理
  2. Excel VBA 函数
  3. 简易版C语言程序设计语法
  4. 彻底卸载Visual Studio 2013、Visual Studio 2015
  5. Maven打包可执行jar
  6. 如何做好presentation
  7. [CareerCup] 1.7 Set Matrix Zeroes 矩阵赋零
  8. SecureCRT显示中文和语法高亮
  9. zeromq
  10. iOS打包ipa安装包的流程
  11. JAVA内置的观察者模式样本
  12. Linux命令记录
  13. css案例学习之table tr th td ul li实现日历
  14. spring中用到的设计模式
  15. 炫龙炎魔T1笔记本 Win7 系统安装
  16. GET和POST传输方式
  17. python 内建函数
  18. (zhuan) Prioritized Experience Replay
  19. HDU1257(dp)
  20. pyspider示例代码七:自动登陆并获得PDF文件下载地址

热门文章

  1. HDU3037 附Lucas简单整理
  2. C# Static修饰符的作用
  3. 费马小定理 Fermat Theory
  4. C# 调用ArcGIS server admin api
  5. PAT 1068. 万绿丛中一点红(20)
  6. 小程序 欢迎页面 navigateTo和tabBar不能同时指向一个路径
  7. Tensorflow瞎搞
  8. ABAP 创建测试文件
  9. 剑指offer 面试42题
  10. idea java web 使用说明