gym102916K. Bloodseeker

本文解析了一个基于CodeForces平台的游戏策略问题,通过优化玩家的生命值管理来确保尽可能多地击败敌人。文章介绍了一种算法,该算法首先将敌人的攻击力调整到玩家的最大生命值范围内,并根据敌人生命值的高低顺序进行排序,以制定最佳攻击顺序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://codeforces.com/gym/102916/problem/K

首先对于所有h=min(h,m)

对于t<=h的,由于它可以更换攻击目标,反正我可以让他们只剩最后一滴血,然后留着最后一滴血的时候再用,就等于备用血包

然后对于t>h的,按h下降顺序排序

In what order should we process enemies from the second group? The right answer is by decreasing hi values. If you process two enemies i and j with hi < hj , you better swap them, processing j first, because your hp will be higher after the first regeneration (after j), and be the same after the second regeneration (after i). If you don’t swap them, the order i, j may fail you because you may not regenerate enough hp after killing i.

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int maxl=2e5+10;
 
int n,m,ans,cnt;
int t[maxl],h[maxl];
struct node
{
	int t,h;
}a[maxl];
 
inline void prework()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&t[i],&h[i]),h[i]=min(h[i],m);
}
 
inline bool cmp(const node &a,const node &b)
{
	return a.h>b.h;
}
 
inline void mainwork()
{
	ll res=m;cnt=0;
	for(int i=1;i<=n;i++)
	if(t[i]<=h[i])
		res+=h[i]-t[i];
	else
		a[++cnt]=node{t[i],h[i]};
	sort(a+1,a+1+cnt,cmp);
	ans=1;
	for(int i=1;i<=cnt;i++)
	{
		res-=a[i].t;
		if(res<0)
			ans=0;
		res+=a[i].h;
	}
}
 
inline void print()
{
	puts(ans?"YES":"NO");
}
 
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值