题目链接:【戳】
更新一下最近做的Codeforces上的题。这场题目相对简单,D题大意是说两个人在玩一款打怪物的游戏,分别输入怪物数n和两个人每秒中能攻击的次数x和y,然后分别输入n个怪物,每个怪物被打多少下会死亡(我们姑且称之为怪物的血量)。问这个是谁打这个怪物的最后一下。
思路:由于两人同时开打,那么每秒都怪物将承受x+y下攻击。所以先将怪物的血量对(x+y)取模,剩下的血量必定在一秒之内可以得到结果。于是乎,我们就自然地想到应该计算出每秒两个人攻击的顺序,只需要把每秒分成x+y份即可。2*10的6次方,完全可以接受。
需要注意下,当刚好为整数秒时,由于他们是同时攻击的,所以输出"Both"。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;
int n;
LL x, y, a;
int s[3000010];
int main() {
scanf("%d%I64d%I64d", &n, &x, &y);
LL mod = x + y - 1;
LL muti = x * y, mx = y, my = x;
for(int i = 1; i <= mod; i++) {
if(mx < my) {
s[i] = 1;//1 == Vanya hit
mx += y;
} else if(mx > my) {
s[i] = 2;
my += x;//2 == Vova hit
} else {
s[i] = 0, s[i + 1] = 0;
i++;
my += x; mx += y;
}
}
for(int i = 1; i <= n; i++) {
scanf("%I64d", &a);
a %= (mod + 1);
if(s[a] == 1) printf("Vanya\n");
else if(s[a] == 2) printf("Vova\n");
else printf("Both\n");
}
return 0;
}