题目链接:
http://acm.hdu.edu.cn/sho
wproblem.php?pid=2187
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct p
{int p,h;}nn[1010];
int cmp(p a,p b)
{return a.p<b.p;}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,k,i;double sum=0;
scanf("%d %d",&m,&k);
for(i=0;i<k;i++)
scanf("%d %d",&nn[i].p,&nn[i].h);
sort(nn,nn+k,cmp);
for(i=0;i<k;i++)
{
if(nn[i].p*nn[i].h<=m) {m-=nn[i].p*nn[i].h;sum+=nn[i].h;}
else {sum+=m*1.0/nn[i].p; break;}
}
printf("%.2f\n",sum);
}
return 0;
}
wproblem.php?pid=2187