其他分享
首页 > 其他分享> > HDU-1009

HDU-1009

作者:互联网

#include <stdio.h> 
#include <math.h>
#include <algorithm>
#define LL long long
#define GG int 
#define For(i, j, k) for(int i=j; i<=k; i++)
#define Dow(i, j, k) for(int i=j; i>=k; i--)
using namespace std;
const int N = 1011; 
struct sFJ{
    int f, j;
    double fj;
} FJ[N];
double ans;
bool cmp(sFJ x, sFJ y){ return x.fj > y.fj;}
int main(){
    int M, n, id;
    while(scanf("%d%d", &M, &n)){
        if(M==-1 && n==-1) break;
        For(i, 1, n){
            scanf("%d%d", &FJ[i].j, &FJ[i].f);
            FJ[i].fj = 1.0 * FJ[i].j / FJ[i].f;
        }
        sort(FJ+1, FJ+n+1, cmp);
        ans = 0;
        For(i, 1, n){
            if(M == 0) break;
            if(M >= FJ[i].f) ans += FJ[i].j, M -= FJ[i].f;
            else ans += FJ[i].fj * M, M = 0;
        }
        printf("%.3lf\n", ans);
    }
    return 0;
}

 

标签:HDU,int,sFJ,1009,ans,fj,include,FJ
来源: https://blog.csdn.net/qq_37264262/article/details/115406822