思路:由于hit的时间涉及浮点数,处理起来较繁琐,所以可以换一种思路。由于所有的monster同时被attack,所以处理1s内的情况即可。预处理一秒内两个人的hit顺序,若同时hit则记为BOTH。
预处理hit次序只需按次数进行扫描,设当前VANYAhit次数为hit_x,VOVA为hit_y,则VANYA的下一次hit时刻为(hit_x + 1)/x,VOVA的下一次hit时刻为(hit_y + 1)/y
①next_x < next_y,说明最近的hit时刻属于VANYA,则此次攻击记录VANYA,hit_x ++
②next_x > next_y,说明最近的hit时刻属于VOVA,则此次攻击记录VOVA,hit_y ++
③next_x = next_y,说明最近的hit时刻两人同时攻击,这两次攻击都记录BOTH,hit_x ++ hit_y++
一秒内hit总和为x+y,所需时间为O(x+y)
代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 2000005
#define VANYA 0
#define VOVA 1
#define BOTH 2
int sta[N], a[100005];
char ans[3][6] = {"Vanya", "Vova", "Both"};
int main(){
int n, x, y;
scanf("%d %d %d", &n, &x, &y);
for(int i = 0; i < n; ++i)
scanf("%d", &a[i]);
int hit_x = 0, hit_y = 0, idx = 0, total = x + y;
while(hit_x < x && hit_y < y){
double next_x = (double)(hit_x + 1) / x, next_y = (double)(hit_y + 1) / y;
if(next_x < next_y)
sta[idx] = VANYA, hit_x ++;
else if(next_x > next_y)
sta[idx] = VOVA, hit_y ++;
else
sta[idx] = BOTH, sta[++idx] = BOTH, hit_x ++, hit_y ++;
++idx;
}
for(int i = 0; i < n; ++i){
int last = (a[i] - 1) % total;
printf("%s\n", ans[sta[last]]);
}
return 0;
}