标签:
#include <string>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <set>
#include <math.h>
#include <stdlib.h>
//using namespace std;
struct type
{
float javabean,food;
float leve;
}num[1010];
int cmp(const void *x, const void *y)
{
return (*(type *)x).leve > (* (type *) y).leve ? -1:1 ;
}
int main()
{
int m,n;
while( ~scanf("%d%d", &m, &n) && m != -1)
{
for(int i=0; i<n; i++)
{
scanf("%f%f", &num[i].javabean, &num[i].food);
num[i].leve = num[i].javabean /num[i].food;
}
qsort(num, n, sizeof(type), cmp);
float max=0;
for(int i=0; i<n; i++)
{
if(m < num[i].food )
{
max += m /num[i].food * num[i].javabean;
break;
}
else
{
max += num[i].javabean;
m -= num[i].food;
}
}
printf("%.3f\n", max);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/sober-reflection/p/fde72b5fea396a4ae2cda9c85acc967c.html