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 ;
}

CodeForces 492D Vanya and Computer Game (思维题)的更多相关文章

  1. Codeforces 492D Vanya and Computer Game

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. CodeForces 492E Vanya and Field (思维题)

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces 718E - Matvey's Birthday(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 首先注意到这个图的特殊性:我们对于所有 \(s_i=s_j\)​ 的 \((i,j)\)​ 之间都连了条边,而字符集大小顶多只有 \(8\ ...

  4. Codeforces 643F - Bears and Juice(思维题)

    Codeforces 题目传送门 & 洛谷题目传送门 首先直接暴力枚举显然是不现实的,我们不妨换个角度来处理这个问题,考虑这 \(R_i\) 个瓶子中每一瓶被哪些熊在哪一天喝过. 我们考虑对这 ...

  5. Codeforces 627E - Orchestra(双向链表,思维题)

    Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in ...

  6. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  7. CodeForces 719A Vitya in the Countryside 思维题

    题目大意:月亮从0到15,15下面是0.循环往复.给出n个数字,如果下一个数字大于第n个数字输出UP,小于输出DOWN,无法确定输出-1. 题目思路:给出0则一定是UP,给出15一定是DOWN,给出其 ...

  8. Codeforces 671 A——Recycling Bottles——————【思维题】

     Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. codeforces 675 C ——Money Transfers——————【思维题】

    Money Transfers time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. Redis高级进阶(二)

    一.消息通知 在一些网站上,经常会有一些发布/订阅或者邮件订阅的功能,尤其一些博客上.其实这种问题很常见,当页面需要进行如发送邮件.复杂的计算时会阻塞页面的渲染.为了避免用户等待太久,应该使用其他进程 ...

  2. jQuery横向手风琴

    在线演示 本地下载

  3. 如何拯救一台glibc被干掉的Linux服务器

    原文: 如何拯救一台glibc被干掉的Linux服务器? 首先如果 libc.so.6 没有被删除, 直接使用LD_PRELOAD就可以恢复 LD_PRELOAD=/lib64/libc-2.12.s ...

  4. 同一台电脑关于多个SSH KEY管理

    运用shh -T -v git@github.com查看具体出错信息,再根据信息来调试    原文链接: http://yijiebuyi.com/blog/f18d38eb7cfee860c117d ...

  5. 1.微信小程序-B站:前言准备

    前言 <微信小程序开发-B站>是以bilibili移动端网站为基础开发微信小程序版本,笔者喜欢的学习是愉快.轻松并能学到实战的东西,不知各位观友有没有一样的经历,就是一有问题不是先去Goo ...

  6. Qt窗口屏幕居中显示

    转自--> http://blog.chinaunix.net/uid-20718335-id-364404.html 窗口的屏幕居中显示问题,在各开发工具中原理相同,首先使用特定的方法得到显示 ...

  7. Storm- 使用Storm实现累积求和的操作

    需求:1+2+3+... = ??? 实现方案: Spout发出数字作为input 使用Bolt来处理业务逻辑:求和 将结果输出到控制台 拓扑设计:DataSourceSpout -->SumB ...

  8. form表单验证失败,阻止表单提交

    form表单验证失败,阻止表单提交 效果演示: 贴上完整代码: <!DOCTYPE html> <html lang="en"> <head> ...

  9. C# 多服务器上传 示例

    图片服务器  带宽越来越不够用,还有当一台服务器的机房出问题的时候,不影响 整个web,以及 考虑网通电信访问服务器的 速度,所以考虑使用多台 图片 服务器 这个时候要求 图片服务器 内容是同步 的  ...

  10. php深入浅出session

    1. session概念 0 2. http协议与状态保持 0 3. 理解cookie 0 4. php中session的生成机制 2 5. php中session的过期回收机制 3 6. php中s ...