codeforce 492 D.Vanya and Computer Game(数学シミュレーション)

1198 ワード

タイトル:http://codeforces.com/problemset/problem/492/D
人によって能力が异なり、一秒の攻撃数が异なり、ゲーム中にn人のモンスターがいて、モンスターにはそれぞれの「血量」(耐えられる最大攻撃数)があり、モンスターごとに最后に谁に致命的な一撃を与えたのかを寻ねる.
例として、
4 3 2
1
2
3
4
1/3(1)  1/2(1/3+1/2)(2)  2/3(1/3+1/2+2/3)(3)  1(1/3+1/2+2/3+1)(4)最后の2人が同时に攻撃し、モンスターは2回のattacksを受ける.点数を整数にする:2 3 4 6(6は1秒と见なす)
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
typedef long long LL;
using namespace std;
const int maxn=2e6+5;
LL q[maxn];
int s[maxn];
int main(int argc, char *argv[]) {
    LL n,x,y;
    while(cin>>n>>x>>y){
    	memset(s,0,sizeof(s));
		LL i,t1=y,t2=x;
		for(i=1;i<=x+y;i++){  //hurts during one and more seconds 
			if(t1<t2){
				s[i]=1;
				t1+=y;
			}
			else if(t1>t2){
				s[i]=2;
				t2+=x; 
			}
			else {
				s[i]=s[++i]=0; // two hurts at same time 
				t1+=y;
				t2+=x;
			}
		}
		for(i=0;i<n;i++){
			LL dex,dex2;
			scanf("%I64d",&dex);
			dex2=dex%(x+y);
			if(s[dex2]==0)printf("Both
"); else if(s[dex2]==1)printf("Vanya
"); else printf("Vova
"); } } return 0; }