码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ-1009 FatMouse' Trade

时间:2015-04-14 00:27:32      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

http://acm.hdu.edu.cn/showproblem.php?pid=1009

# include <stdio.h>
# include <algorithm>
# define MAX 1010
using namespace std;

struct NODE
{
	int j, f;
	double avg;
}food[MAX];

int n, m;

int cmp(const NODE& a, const NODE& b)
{
	return a.avg > b.avg;
}

int main()
{
	while(scanf("%d %d", &m, &n) && m != -1 && n != -1)
	{
		for(int i = 0; i < n; i++)
		{
			scanf("%d %d",&food[i].f, &food[i].j);
			food[i].avg = food[i].f * 1.0 / food[i].j;
		}sort(food, food+n, cmp);

		double ans = 0;
		for(int i = 0; i < n; i++)
		{
			if(m > food[i].j)
			{
				ans += food[i].f;
				m -= food[i].j;
			}
			else
			{
				ans += (m * 1.0 / food[i].j * food[i].f);
				m = 0;
				break;
			}
		}
		printf("%.3lf\n", ans);
	}
	
	return 0;
}

  

HDOJ-1009 FatMouse' Trade

标签:

原文地址:http://www.cnblogs.com/linjiaman/p/4423545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!