hdu 2570 (贪心)

点击打开链接


注意浓度的算法


#include"stdio.h"
#include"algorithm"
using namespace std;
int main()
{
	int t;
	int i;
	int n,v;
	int w,p[101];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d",&n,&v,&w);
		for(i=0;i<n;i++)
			scanf("%d",&p[i]);
		int V;
		double P;
		V=0;P=0;i=0;
		sort(p,p+n);
		while(P*V+p[i]*v<=w*(V+v)&&i<n)
		{
			
			P=(P*V+p[i]*v)/(V+v);
			V+=v;
			i++;
		}
		printf("%d %0.2f\n",V,P/100);
	}
	return 0;
}

	


原文地址:https://www.cnblogs.com/yyf573462811/p/6365131.html