本地能过,提交全RE
查看原帖
本地能过,提交全RE
1304731
封禁用户楼主2024/8/29 18:33

代码:

#include<bits/stdc++.h>
using namespace std;
double n,t,a,b;
struct element
{
	double price=1,weight=-1;
}x[107];
bool cmp(element x,element y)
{
	return x.price<y.price;
}
double check(double u,int h,double money)
{
	if(x[h].weight==-1.0) return money;
	if(u==0) return money;
	if(x[h].weight<=u)
	{
		double now=money+(x[h].price*x[h].weight);
		check(u-x[h].weight,h+1,now);
	}
	else
	{
		double now=money+((x[h].weight-u)*x[h].price);
		check(0,h+1,now);
	}
}
int main()
{
	cin>>n>>t;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		x[i].weight=a;
		x[i].price=b/a;
	}
	sort(x,x+int(n),cmp);
	cout<<fixed<<setprecision(2)<<check(t,0,0);
	return 0;
}

2024/8/29 18:33
加载中...