D. Vanya and Computer Game
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputVanya 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.
InputThe 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.
OutputPrint 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.
Sample test(s) Input4 3 2 1 2 3 4Output
Vanya Vova Vanya BothInput
2 1 1 1 2Output
Both Both题意:此题就是以一分钟内两人的子弹数为一个周期,标记当前是哪颗子弹即可。(ps:刚开始看错了题意想了一个多小时也是醉了...)
代码清单:
#include
#include
#include
using namespace std; typedef long long ll; ll vis[2000000+5]; int main() { ll n,x,y,m; cin>>n>>x>>y; ll sx=y,sy=x; for(ll i=1;i<=(x+y);i++) { if(sx
sy) { vis[i]=2; sy+=x; } else { vis[i]=vis[i+1]=3; i++; sx+=y; sy+=x; } } vis[0]=3; while(n--) { cin>>m; m%=(x+y); if(vis[m]==1) cout<<"Vanya\n"; if(vis[m]==2) cout<<"Vova\n"; if(vis[m]==3) cout<<"Both\n"; } return 0; }