#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
class room
{
public:
int javabin;
int catfood;
double per;
public:
room(){}
void renew(int j,int c)
{
javabin=j;
catfood=c;
per=(double)j/c;
}
bool operator<(room b)
{
return per<b.per;
}
void show() //用来测试的
{
cout<<javabin<<" "<<catfood<<" "<<per<<endl;
}
};
room ROOM[1005];
int main()
{
int M,N;
int ja,fo;
while(cin>>M>>N)
{
if(M==-1&&N==-1)break;
double sum=0;
for(int i=0;i<N;i++)
{
cin>>ja>>fo;
ROOM[i].renew(ja,fo);
}
sort(ROOM,ROOM+N);
// for(int i=0;i<N;i++)
// {
// ROOM[i].show();
// }
for(int i=N-1;i>=0;i--)
{
if(ROOM[i].catfood<=M)
{
sum+=ROOM[i].javabin;
M-=ROOM[i].catfood;
}
else
{
sum+=M*ROOM[i].per;
break; //已经是没有猫粮了
}
}
printf("%.3lf\n",sum);
}
return 0;
}
hdu1009 贪心(简单题)
最新推荐文章于 2021-11-13 14:44:42 发布