#王道机试指南第二版,第119页,题目:FatMouse'Trade自己的代码:(只为做个记录)#include(720)#includeusing namespace std;struct ROOM{double j;double f;double xingjiabi;};ROOM room[1000];//降序bool comp(ROOM a,ROOM b){if(a.xingjiabi>b.xingjiabi){return true;}else{return false;}}int main(){int M,N;while(cin>>M>>N && M!=-1 &&N!=-1){for(int i=0;icin>>room[i].j>>room[i].f;room[i].xingjiabi=room[i].j/room[i].f;}sort(room,room+N,comp);double shuchu=0;int k=0,p=0;while(M>0){p=M-room[k].f;if(p >=0){shuchu=room[k].j+shuchu;M=M-room[k].f;}else{shuchu=shuchu+M/room[k].f*room[k].j;M=M-room[k].f;}k++;}printf("%.3f",shuchu);}return 0;}