CodeForces 492D Vanya and Computer Game (思维题)
2 seconds
256 megabytes
standard input
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.
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.
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.
4 3 2
1
2
3
4
Vanya
Vova
Vanya
Both
2 1 1
1
2
Both
Both
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 (思维题)的更多相关文章
- 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 ...
- CodeForces 492E Vanya and Field (思维题)
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 718E - Matvey's Birthday(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 首先注意到这个图的特殊性:我们对于所有 \(s_i=s_j\) 的 \((i,j)\) 之间都连了条边,而字符集大小顶多只有 \(8\ ...
- Codeforces 643F - Bears and Juice(思维题)
Codeforces 题目传送门 & 洛谷题目传送门 首先直接暴力枚举显然是不现实的,我们不妨换个角度来处理这个问题,考虑这 \(R_i\) 个瓶子中每一瓶被哪些熊在哪一天喝过. 我们考虑对这 ...
- Codeforces 627E - Orchestra(双向链表,思维题)
Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in ...
- 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 ...
- CodeForces 719A Vitya in the Countryside 思维题
题目大意:月亮从0到15,15下面是0.循环往复.给出n个数字,如果下一个数字大于第n个数字输出UP,小于输出DOWN,无法确定输出-1. 题目思路:给出0则一定是UP,给出15一定是DOWN,给出其 ...
- Codeforces 671 A——Recycling Bottles——————【思维题】
Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 675 C ——Money Transfers——————【思维题】
Money Transfers time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- var妙用
var广泛使用其实也有用的.比如在一些不太确定类型的地方 (比如要区分int/uint/long/double的时候),用泛型太牛刀而不用又觉得不灵活的时候,其实是比较推荐var的比如设计某种类的时候 ...
- Docker Copy On Write
Container分成结构 Container最上面是一个可写的容器层,以及若干只读的镜像层组成,Container的数据就存放在这些层中,这样的分层结构最大的特性是Copy-On-Write: 1. ...
- NetBeans字体设置
01.找到自己java字体目录.我的目录是[C:\Program Files\Java\jdk1.7.0_21\jre\lib] 02.复制fontconfig.properties.src, 重命名 ...
- bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 优先队列+dij
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1768 Solv ...
- Neutron Callback System
用于core and service components之间的通信,传递resource的lifecycle events (e.g. before creation, before deletio ...
- php简单实现通讯录采集,我的第一个php,适合新手
起源于要整理通讯录,原先用的是文件调查,现在学了php,就自己试一下.程序短小精悍,适于学习.有两个文件,bj.html用于显示和采集表单信息.bj.php用于处理数据和反馈结果.突出之处在于可以上传 ...
- SQL Server convet函数data_type默认长度
语法 CONVERT(data_type(length),data_to_be_converted,style) data_type(length) 规定目标数据类型(带有可选的长度),默认30个字符 ...
- Activity间数据传输
当对Android有一些了解后,不难发现,Android程序UI框架接近于Web页面的概念.每一个用于呈现页面的组件,Activity,都是彼此独立的,它们通过系统核心来调度整合,彼此之间的通过Int ...
- c/c++写的比较好的读写配置文件的函数或者类
共用版 .h文件 //---------------------------------------------------------------------------- // 程序名称: ...
- 多级联动下拉菜单--cxSelect
jquery cxSelect插件 github地址:https://github.com/ciaoca/cxSelect demo地址:http://code.ciaoca.com/jquery/c ...