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. shell单例-处理方案

    shell单例:当某一个shell脚本需要重复执行时(shell定时任务 etc),为了避免多个相同任务之间交叉,造成数据的混乱或者错误,需要脚本单例执行. 就是前一个进程执行时,后一个进程需要阻塞等 ...

  2. 剑指offer——求1+2+...+n

    方法一.通过在类的构造函数中执行加的过程. #include <iostream> using namespace std; class Base { public: Base(){n++ ...

  3. EntityFramework 学习 一 DbSet

    DBSet类表示一个实体的集合,用来创建.更新.删除.查询操作,DBSet<TEntity>是DBSet的泛型版本 你可以使用DbContext获取DBSet的引用,例如dbContext ...

  4. LINQ 学习路程 -- 查询操作 Average Count Max Sum

    IList<, , }; var avg = intList.Average(); Console.WriteLine("Average: {0}", avg); IList ...

  5. ruanjiangongcheng1

    软体工程的方法有很多方面的意义.包括专案管理,分析,设计,程序的编写,测试和质量控制. 软体设计方法可以区别为重量级的方法和轻量级的方法.重量级的方法中产生大量的正式文档. 著名的重量级开发方法包括I ...

  6. java学习进度条四

  7. IIS 高并发导致log记录不完全

    项目测试性能过程中,对于高并发测试过程中发现log记录缺失一部分,经过调查,找到了原因是因为IIS连接数的限制,经过修改连接数,成功完成.设置如下: “点击网站”->“右击切换到功能视图”-&g ...

  8. vscode 小笔记

    用户设置: { "git.ignoreMissingGitWarning": true, "workbench.statusBar.feedback.visible&qu ...

  9. 获取window状态栏和标题栏的高度

    1.获取状态栏高度: decorView是window中的最顶层view,可以从window中获取到decorView,然后decorView有个getWindowVisibleDisplayFram ...

  10. git克隆某一个branch

    git clone -b <branch> <remote_repo> 例如: git clone -b 指定的分支名字