Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理

思路:由于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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值