codeforce 492D. Vanya and Computer Game(数学模拟)

题目: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) 最后两个人同时攻击,怪物承受两次attacks。将分数化成整数:2 3 4 6(6看做一秒)

#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\n");
			else if(s[dex2]==1)printf("Vanya\n");
			else printf("Vova\n");
		}
    }
    return 0;
}


你可能感兴趣的:(codeforce)