80分求助
查看原帖
80分求助
637790
xhz2018楼主2024/7/12 21:28
#include <bits/stdc++.h>
using namespace std;

int n, t;
struct node
{
	int m, v;
	double sc;//sc是性价比
}k[1000005];

bool cmp(node x, node y)
{
	return x.sc > y.sc;
}

int main()
{
	cin >> n >> t;
	for (int i = 1; i <= n; i++)
	{
		cin >> k[i].m >> k[i].v;
		k[i].sc = k[i].v*1.0 / k[i].m;
	}
	sort (k + 1, k + n + 1, cmp);
	double ans = 0.0;
	int cur = 1;
	while (t > 0)
	{
		if ( t - k[cur].m >= 0)//若足够带走整堆,则带走 
		{
			t -= k[cur].m;
			ans += k[cur].v;
			cur++;
		}
		else//否则尽量带 
		{
			ans += (1.0*k[cur].v/k[cur].m) * t;
			t = 0; 
		}
	}
	printf("%.2lf", ans);
	return 0;
}
2024/7/12 21:28
加载中...