题目:
样例:
代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
struct room{
double j;
double f;
double rate;
}rooms[1010];
bool cmp(room a,room b){
return a.rate>b.rate;
}
int main(){
double m;
int n;
while(1){
scanf("%lf%d",&m,&n);
if(m==-1||n==-1){
break;
}
for(int i=0;i<n;i++){
scanf("%lf%lf",&rooms[i].j,&rooms[i].f);
rooms[i].rate=rooms[i].j/rooms[i].f;
}
sort(rooms,rooms+n,cmp);
double rest=m;//还能选择的猫粮
int k;
double maxfood=0;
for(int i=0;i<n;i++){
if(rest>rooms[i].f){
rest=rest-rooms[i].f;
maxfood+=rooms[i].j;
}
else if(rest<=rooms[i].f){
maxfood+=rest*rooms[i].rate;
break;
}
}
printf("%.3f\n",maxfood);
}
return 0;
}