10分求调,必关
查看原帖
10分求调,必关
1769771
GEYIHAO楼主2025/7/26 15:58
#include<bits/stdc++.h>
using namespace std;
struct node{
	int w,v,p;
}a[105];
bool cmp(node x,node y){
	return x.p>y.p;
}
int main(){
	int n;
	double sum,c;
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>a[i].w>>a[i].v;
		a[i].p=a[i].v/a[i].w;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		if(c>=a[i].w){
			c-=a[i].w;
			sum+=a[i].v;
		}else{
			sum+=c*a[i].p;
			break;
		}
	}
	printf("%.2f",sum);
	return 0;
}

求助

2025/7/26 15:58
加载中...