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. Cocos2d-x Lua中帧动画

    帧动画就是按一定时间间隔.一定的顺序.一帧一帧地显示帧图片.我们的美工要为精灵的运动绘制每一帧图片,因此帧动画会由很多帧组成,按照一定的顺序切换这些图片就可以了. 在Cocos2d-x Lua中播放帧 ...

  2. Java基础 - 流程控制语句

    package com.demo4; /* * 流程控制语句 * 流程控制语句分类: * 顺序结构 * 代码从上往下按照顺序执行 * * 选择结构 * if * if (关系表达式1) { * 语句体 ...

  3. ES6学习笔记(一)——let和const

    1.ES6学习之let.const (1).var.let.const 变(常)量声明 ES5 只有全局作用域和函数作用域,没有块级作用域,这带来很多不合理的场景. 在ES6中let就诞生了,实际上它 ...

  4. ng-disabled的使用

    1.适用范围 该指令适用于<input>, <select>,<button> 和 <textarea> 元素. 2.用法解析 ng-disabled ...

  5. yum命令的实例

    1) 自定义yum仓库:createrepo 2) 自定义repo文件 3) 使用yum命令安装httpd软件包(在这里需要强调一点,本身执行yum.repos.d时,文件里面是有自带的yum源的,需 ...

  6. linux安装jdk_1.8

    转载自http://blog.csdn.net/ldl22847/article/details/7605650 1.下载jdk的rpm安装包,这里以jdk-8u141-linux-x64.rpm为例 ...

  7. app开发制作会难吗?app开发好学吗?

    前面我们讲到了app是什么,APP是运行在智能手机的第三方应用程序,可以满足用户的不同需求.那么app开发制作会难吗?这个与产品的复杂度有很大的关系,复杂度包括业务逻辑多不多,业务模块多不多等,对于玩 ...

  8. Mybatis参数总结(转载)

    转载自: MyBatis传入多个参数的问题 mybatis传递参数总结 一.单个参数 1.基本数据类型 (1)直接使用 List<ChargeRuleDO> tests(long id); ...

  9. SUBMIT RM07DOCS【MB51】 获取返回清单,抓取标准报表数据

    *&---------------------------------------------------------------------* *& Report YT_SUBMIT ...

  10. ACM解题之(ZOJ 2212) Argus

    题目来源: 点击打开题目 题目翻译: 数据流是实时的,连续的,有序的项目序列.一些例子包括传感器数据,互联网流量,金融代码,在线拍卖以及诸如网络使用日志和电话记录之类的交易日志.同样,对流进行的查询在 ...