求助大佬
查看原帖
求助大佬
318876
金城武楼主2020/6/30 16:29
#include <bits/stdc++.h> 
using namespace std;
int n,m;
double u;
struct JB
{   int c;
	int v;
	double p; 
}jb[101];
bool cmp(JB x,JB y)
{
	return x.p>y.p;
}
int main ()
{cout<<fixed<<setprecision(2)<<endl;
	cin>>n>>m;
	
	for (int i=1;i<=n;i++)
	{
		cin>>jb[i].c>>jb[i].v;
		jb[i].p=jb[i].v/jb[i].c;
	}
	sort(jb+1,jb+n+1,cmp);
	for (int i=1;i<=n;i++)
	{
		if (m>jb[i].c)
		{
			u+=jb[i].v;
			m-=jb[i].c;
		}
		else
		{
			u+=m*jb[i].p;
			break;
		}
	}
	cout<<u;
  return 0;
}
2020/6/30 16:29
加载中...