原题: http://acm.hdu.edu.cn/showproblem.php?pid=1009
//题目大意:有一只老鼠,它有m磅猫爱吃的粮食。现在有n个猫房子,里面分别有j[i]磅老鼠爱吃的豆子,如果想把其中所有的豆子偷出来,需要f[i]磅的粮食去引诱猫出房子, 如果老鼠想偷其中的j[i] * a% 磅的豆子,就需要付出f[i]*%a磅猫爱吃的粮食
//问已知老鼠现有的粮食总数,和各猫房子的信息,怎么样才能拿到最多的豆子bean//类似可分割的01背包问题。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct H
{
double j;
double f;
}h[1001];
int cmp(H a,H b)
{
return a.j*b.f>b.j*a.f;
}
int main()
{
int m;
double n;
scanf("%lf %d",&n,&m);
while(!(n==-1 && m==-1))
{
for(int i=1;i<=m;i++)
{
scanf("%lf %lf",&h[i].j,&h[i].f);
}
sort(h+1,h+1+m,cmp);
double all=0;
for(int i=1;i<=m;i++)
{
if(n>h[i].f)
{
n=n-h[i].f;
all=all+h[i].j;
}else{
all=all+n*h[i].j/h[i].f;
break;
}
}
printf("%.3lf\n",all);
scanf("%lf %d",&n,&m);
}
return 0;
}