Gym102916K. Bloodseeker 贪心

Link
贪心

题意

一个吸血鬼 有 m m m 滴血的上限,一开始满血,每秒钟会掉一滴血,且可以对一个怪物造成1点伤害,有 n n n个 怪物,每个怪物有 t i t_i ti滴血,击杀一个怪物后可以回复 h i h_i hi 滴血,但是不能超过上限,问是否可以击杀所有怪物

思路

首先由于恢复体力后体力也不能超过上限,所以预处理 h i = m i n ( m , h i ) h_i=min(m,h_i) hi=min(m,hi)
1.由于可以更改攻击目标,所以若 h i ≥ t i h_i \geq t_i hiti,则可以回复 h i − t i h_i-t_i hiti 点血量
2.若 h i < t i h_i < t_i hi<ti,考虑 i   j i\ j i j 两个怪物先后杀的顺序,会导致最低的血量不同,写一下式子,发现先杀回复量大的怪即可,所以按照 h i h_i hi 从大到小排序。

代码

int n, m;
struct Node {
	int t, h;
	/*
	bool operator < (const Node &x) const {
		if(h-t>0 &&  (x.h-x.t) <= 0)
			return 1;
		if(h-t>0 && (x.h-x.t)>0)
			return t < x.t;
		return h > x.h;
	}
	*/
	bool operator < (const Node &x) const {
		return h > x.h;
	}
}node[maxn];
void solve() {
    cin >> n >> m;
    int q = m;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
    	int t, h;
    	cin >> t >> h;
    	h = min(h, m);
    	if(h - t > 0) {
    		q += h - t;
    	}
    	else {
    		node[++cnt] = (Node){t, h};
    	}
    }
    sort(node + 1, node + cnt + 1);
    for(int i = 1; i <= cnt; i++) {
    	// cout << node[i].t << ' ' << node[i].h << endl;
    	if(q < node[i].t) {
    		cout << "NO\n";
    		return;
    	}
    	q -= node[i].t - node[i].h;
    }
    cout << "YES\n";
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值