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

Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学的更多相关文章

  1. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

    D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  2. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 预处理

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

  3. Codeforces Round #280 (Div. 2) E. Vanya and Field 数学

    E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  4. Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心

    C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  5. Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...

  6. Codeforces Round #280 (Div. 2)_C. Vanya and Exams

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. Codeforces Round #280 (Div. 2) E. Vanya and Field 思维题

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

  8. Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table

    题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...

随机推荐

  1. Using InfluxDB in Grafana,influxDB在grafana中使用

    grafana带有功能丰富的数据源插件influxDB.支持丰富的查询编辑器.注释和templating(模版)查询. 增加数据源(Adding the data source) 点击顶部Grafan ...

  2. _utf8_encode _utf8_decode base64_encode base64_decode

    const Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv ...

  3. PAT 1070. 结绳(25)

    给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连.每次串连后,原来两段绳子的长度 ...

  4. CSDN论坛停站维护公告

    各位亲爱的用户:         CSDN论坛将于2014年11月9日23点至11月10日8点进行积分系统的升级,升级期间会影响大家的正常訪问和操作.给大家带来不便,敬请广大用户谅解.         ...

  5. 协程 Gevent

    # 协程应用:爬虫 from gevent import monkey;monkey.patch_all() import gevent import requests import time def ...

  6. SQL Server误删表查看

    SQL Server误删表查看 转自:http://blog.51cto.com/aimax/2134572   SQL Server 完全恢复模式 下恢复误删除的表,进行 精准 恢复 1.  找出被 ...

  7. 关于“Cannot find any provider supporting AES/ECB/PKCS7Padding”问题的解决方案

    出现这个问题的原因是:java自带的是PKCS5Padding填充,不支持PKCS7Padding填充 参考:https://stackoverflow.com/questions/20770072/ ...

  8. Nginx图片及样式文件不记录访问日志

    1.Nginx作为web服务器是可直接在server配置文件中做如下配置: server { listen ; server_name www.fansik.com; access_log /data ...

  9. windows8.1电话激活密钥

    请断网安装Windows 8.1核心版:334NH-RXG76-64THK-C7CKG-D3VPT Windows 8.1专业版:XHQ8N-C3MCJ-RQXB6-WCHYG-C9WKB

  10. 备注字段长度控制JS

    //变更原因备注字符长度控制 function checkChangeLength() { var field = $("#changeReasonDesc").val(); ma ...