Codeforces Round #617 (Div. 3) D. Fight with Monsters(思维博弈)

Fight with Monsters:

题目大意:(文末有原题)

给出n个怪物的血量,你每次可以对他造成a点伤害,你的对手则能打b点,你先打,你的技能是让对手不能出招(能使用k次),判断你最多能造成几次致命一击;

思路:

(因为n和a,b都比较大,所以应该很大可能直接暴力会TLE(我也没试))

因为要获得最大的致命一击,所以要尽可能多的在对手要造成最后一击的时候对他使用技能(这样就等于说之前对手是在给你打工);所以我们只要统计出 对于每个怪物如果你想要致命一击 需要使用多少次技能,最后再对次数排序,从头开始加,直到技能释放完或者释放了也没用的情况;

代码:

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const ll maxn = 2e5 + 10;
ll x[maxn];		//用于记录 对第i个怪物想要获得致命一击需要释放技能的次数 

int main() {
	ll n, a, b, k, ans = 0;
	cin >> n >> a >> b >> k;
	
	for(ll i = 0; i < n; i++){	
		ll v; cin >> v;
		v = v % (a + b);	//判断对手最后一次攻击后还剩多少血; 
		if(v == 0) v += a + b;	//如果没血了,就不能让对手进行最后一次攻击了; 
		if(a >= v) x[i] = 0;	//如果剩下的血 a一次攻击能杀死,则不需要释放技能; 
		else {		//如果每次轮到对手攻击就释放技能,那么 如果你攻击了x次,需要始放x-1次技能; 
			if(v % a) x[i] = v / a;
			else x[i] = v / a - 1;
		} 
	}
	
	sort(x, x + n);
	
	for(ll i = 0; i < n; i++) {
		k -= x[i];
		ans++;
		if(k < 0) {	//k = 0时,有可能下一个怪物不需要释放技能就能获胜,所以要 k < 0; 
			ans--;
			break;
		}
	}
	
	cout << ans << endl;
	return 0;
}

原题:

题目:

There are nn monsters standing in a row numbered from 1 to n. The ii-th monster has hi health points (hp). You have your attack power equal to aa hp and your opponent has his attack power equal to bb hp.

You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to 0.

The fight with a monster happens in turns.

  1. You hit the monster by a hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.
  2. Your opponent hits the monster by b hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster.

You have some secret technique to force your opponent to skip his turn. You can use this technique at most kk times in total (for example, if there are two monsters and k=4, then you can use the technique 2 times on the first monster and 1 time on the second monster, but not 2 times on the first monster and 3 times on the second monster).

Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.

输入:

The first line of the input contains four integers n,a,b and kk (1≤n≤2⋅10^5,1≤a,b,k≤10^9) — the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique.

The second line of the input contains nn integers h1,h2,…,hn (1≤hi≤10^9), where hihi is the health points of the i-th monster.

输出:

Print one integer — the maximum number of points you can gain if you use the secret technique optimally.

样例:

Input:

6 2 3 3

7 10 50 12 1 8

Output:

5

Input:

1 1 100 99

100

Output:

1

Input:

7 4 2 1

1 3 5 4 2 7 6

Output:

6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值