为什么我的程序不输出 求巨佬点拨
查看原帖
为什么我的程序不输出 求巨佬点拨
927789
Xincheng_Wang楼主2023/7/17 10:45
#include<bits/stdc++.h>
using namespace std;
#define double long long
double n,m,ans;
struct node{
	double v,w;
}a[107];
double cmp(node x,node y){
	if(x.v<y.v)return y.v;
	return x.v;
}
int main(){
	scanf("%lf %lf",&n,&m);
	for(int i=1;i<=n;i++)scanf("%lf %lf",&a[i].v,&a[i].w);
	sort(a+1,a+1+n,cmp);
//	for(int i=1;i<=n;i++)printf("%lf %lf\n",a[i].v,a[i].w);
	for(int i=1;i<=n;i++){
		if(m-a[i].w>=0){
			m-=a[i].w;
			ans+=a[i].w*a[i].v;
		}
		else{
			ans+=a[i].v/a[i].w*m;
			break;
		}
	}
	printf("%.2lf",ans);
}
2023/7/17 10:45
加载中...