专栏文章

T541183题解

个人记录参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@mir3ucvw
此快照首次捕获于
2025/12/04 15:18
3 个月前
此快照最后确认于
2025/12/04 15:18
3 个月前
查看原文

T541183\color{000000}{T541183} 题解

这题很简单,只需要将所有敌人按暴力值排个序,将还没花完的能量依次减去,最后排回来即可。
代码:
CPP
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+5;
struct dellar{
	string o;
	int p;
	int dsize;
	bool flag=false;
}a[MAX];
int n,m;
bool cmp1(dellar x,dellar y){
	return x.p<y.p;
}
bool cmp2(dellar x,dellar y){
	return x.dsize<y.dsize;
}
int main(){
	cin>>n>>m;
	if(n==0){
		cout<<0;
		exit(0);
	}
	for(int i=0;i<n;i++)cin>>a[i].o>>a[i].p,a[i].dsize=i;
	sort(a,a+n,cmp1);
	int i=0;
	while(m-a[i].p>=0 && i<n){
		m-=a[i].p;
		a[i].flag=true;
		i++;
	}
	cout<<i<<endl;
	sort(a,a+n,cmp2);
	for(int i=0;i<n;i++){
		if(a[i].flag)cout<<a[i].o<<endl;
	}
	return 0;
}

如果你也要提交题解,欢迎在下方留言!

评论

0 条评论,欢迎与作者交流。

正在加载评论...