Codeforces Round #280 (Div. 2) D. 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.
题意: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 数学的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...
- 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 ...
- 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 ...
- 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 ...
- 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...
随机推荐
- codevs1058 合唱队形==洛谷P1091 合唱队形
P1091 合唱队形 题目描述 N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学排成合唱队形. 合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1,2…,K,他们的 ...
- django database relations
注意Django的生成的默认api from django.db import models class Place(models.Model): ''' pass class Restaurant( ...
- phpwind 论坛 转移
前段时间用phpwind 搭建了一个本地论坛系统,也写过一篇随笔,讲phpwind论坛的迁移,昨天网上又对论坛做了迁移,在本地搭建了系统. 使用的是之前没有成功的方法.这种方法挺方便的,之前每次都是重 ...
- 好的commit应该长啥样 https://github.com/torvalds/linux/pull/17#issuecomment-5654674
Git commits历史是如何做到如此清爽的? - 知乎 https://www.zhihu.com/question/61283395/answer/186122300 尤雨溪 前端开发.Java ...
- qt 如何给图元安装一个场景事件过滤器?
void QGraphicsItem::installSceneEventFilter(QGraphicsItem *filterItem) class LabCrossEvent : public ...
- centos中screen的使用 创建 退出
一.创建一个新窗口: 安装完成后,直接敲命令screen就可以启动它.但是这样启动的screen会话没有名字,实践上推荐为每个screen会话取一个名字,方便分辨: [root@elk-server ...
- gearman管理
通常,Gearman被用来分发任务,以便实现异步操作.下面捋捋如何管理Gearman. 说明:请自行安装好Gearman和PHP PECL Gearman. (我之前安装的gearman php的c语 ...
- yii2弹出层
bootstrap http://getbootstrap.com/javascript/#modals https://github.com/lichunqiang/yii2-sweet-submi ...
- 【转】通过fio工具,测试SATA,SAS,SSD 读写性能
转自:http://blog.csdn.net/killmice/article/details/42745937
- Adjust Linux Mint Mouse Scroll (Normal/Reverse)
Set Scroll Normal 1 echo "pointer = 1 2 3 4 5 6 7 8 9 10 11 12" > ~/.Xmodmap && ...