「CF492D」Vanya and Computer Game
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.
1 2 3 4 5 |
4 3 2 1 2 3 4 |
1 2 3 4 |
Vanya Vova Vanya Both |
1 2 3 |
2 1 1 1 2 |
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.
题解
设1/xy为一个单位时间
t个单位时间时a攻击t/y次,b攻击t/x次
可以打表或者二分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<map> #include<ctime> #include<vector> #include<set> #include<cmath> #include<algorithm> #define inf 1000000000 #define ll long long #define pa pair<int,int> using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,x,y; int main() { n=read();x=read();y=read(); for(int i=1;i<=n;i++) { int t=read(); ll l=0,r=1e15,ans; while(l<=r) { ll mid=(l+r)>>1; if(mid/x+mid/y>=t)ans=mid,r=mid-1; else l=mid+1; } if(ans%x==0&&ans%y==0)puts("Both"); else if(ans%x)puts("Vanya"); else puts("Vova"); } return 0; } |