FatMouse' Trade 贪心
不知道为啥wa 思路是对的
还有涉及double 的要考虑精度
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
class ss
{
public:
int id;
double value;
bool operator<(const ss& s)const
{
return value<s.value;
}
}sss[1004];
int main()
{
priority_queue<ss> k;
double n,m,a[1002],b[1002];
while(cin>>n>>m)
{
if(n==-1)break;
while(!k.empty()) k.pop();
for(int i=0;i<m;i++)
{
cin>>a[i]>>b[i];
sss[i].id=i;
sss[i].value=a[i]/b[i];
k.push(sss[i]);
}
ss t;
double sum=0;
while(!k.empty())
{
t=k.top();
if(n-b[t.id]<0.0001) break;
k.pop();
sum+=a[t.id];
n-=b[t.id];
}
sum+=n*a[t.id]/b[t.id];
printf("%.3lf\n",sum);
}
return 0;
}