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 ;
}
最新文章
- Spring Boot中的事务管理
- Excel VBA 函数
- 简易版C语言程序设计语法
- 彻底卸载Visual Studio 2013、Visual Studio 2015
- Maven打包可执行jar
- 如何做好presentation
- [CareerCup] 1.7 Set Matrix Zeroes 矩阵赋零
- SecureCRT显示中文和语法高亮
- zeromq
- iOS打包ipa安装包的流程
- JAVA内置的观察者模式样本
- Linux命令记录
- css案例学习之table tr th td ul li实现日历
- spring中用到的设计模式
- 炫龙炎魔T1笔记本 Win7 系统安装
- GET和POST传输方式
- python 内建函数
- (zhuan) Prioritized Experience Replay
- HDU1257(dp)
- pyspider示例代码七:自动登陆并获得PDF文件下载地址