本文主要是介绍FatMouse\' Trade -HUD1009,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://acm.hdu.edu.cn/showproblem.php?pid=1009
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 1000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
double J[maxn],F[maxn];
struct node
{
double t;
int id;
}nod[maxn];
bool cmp(node a,node b)
{
return a.t>b.t;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m;
while(cin>>m>>n)
{
if(m==-1&&n==-1)break;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&J[i],&F[i]);//
nod[i].id=i;
nod[i].t=(1.0*J[i]/F[i]);
}
sort(nod+1,nod+1+n,cmp);
double ans=0;
for(int i=1;i<=n;i++)
{
if(m==0)break;
if(F[nod[i].id]<=m)
{
m=m-F[nod[i].id];
ans+=J[nod[i].id];
}
else
{
ans+=((1.0*m)/F[nod[i].id])*J[nod[i].id];
m=0;
}
}
printf("%.3lf\n",ans);
}
return 0;
}
这篇关于FatMouse\' Trade -HUD1009的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!