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-;
const int N = *;
ll cas = ; char s[][]={"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 = ; i<=xy ; i++)
{
if(xx < yy)
{
who[i] = ;
xx += x;
}
else
{
who[i] = ;
yy += y;
}
}
ll a;
for(ll i = ; i <= n; i ++ )
{
scanf("%I64d",&a);
a %= xy;
if(a== || a==xy-)
puts(s[]);
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 ;
}

最新文章

  1. PK淘宝BUY+,京东推出AR购物应用JD Dream
  2. Ubuntu+Apache2+Mono+MVC3
  3. 关于Java反射机制的几个问题
  4. ASP.NET发布网站遇到的几个问题
  5. angularjs-$interval使用
  6. jsmooth 中文乱码
  7. 第六十八篇、OC_按照某一字段对数值进行排序
  8. C++ primer(八)--内联函数 引用变量 引用传递函数参数 函数重载/模板/模板具体化
  9. Nginx源码研究二:NGINX的事件处理概论
  10. RMAN学习笔记
  11. openui5的资料比较少
  12. HTML5之appcache语法理解/HTML5应用程序缓存/manifest缓存文件官方用法翻译
  13. [置顶] Xamarin android如何调用百度地图入门示例(一)
  14. 阿里云API网关(15)监控预警
  15. 磁盘上没有足够的空间完成此操作的解决办法_Windows小知识
  16. mac电脑设置USB键盘按键方法,设置多显示屏镜像显示器的方法
  17. 将数据挂载到 docker 容器中的3种方式:volume、bind mount、tmpfs
  18. 【原】Ubuntu virtual terminal
  19. android 系统开发板挂载U盘
  20. Java Learning之文档注释

热门文章

  1. selenium主要功能封装
  2. CSS3分享按钮动画特效
  3. CreateProcess 执行CMD命令,并重定向输出
  4. 012_流式计算系统(Mahout协同过滤)
  5. JavaScript基础挖掘目录
  6. node.js+express验证码的实现
  7. QFileInfo与QFileIconProvider(分别用于获取文件信息和获取文件的图标)
  8. python的函数式编程知识小结
  9. 4445: [Scoi2015]小凸想跑步 半平面交
  10. 使用UIBezierPath添加投影效果