首页 > 其他 > 详细

B1020

时间:2019-10-30 21:21:02      阅读:93      评论:0      收藏:0      [点我收藏+]
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
struct P{
    double need;//库存 
    double value;//总价 
    double s_mon;//单价 
};
bool cmp(P a, P b){
    return a.s_mon > b.s_mon;
}
int main(){
    int N;
    double D;
    double sum_mon = 0;
    cin >> N >> D;
    P product[N];
    for(int i = 0; i < N; i++){
        scanf("%lf", &product[i].need);
    }
    for(int i = 0; i < N; i++){
        scanf("%lf", &product[i].value);
        product[i].s_mon = product[i].value/product[i].need;
    }
    sort(product, product+N, cmp);
    for(int i = 0; i < N; i++){
        if(product[i].need <= D){
            sum_mon = sum_mon + product[i].value;
            D = D - product[i].need;    
        }else if(product[i].need > D){
            sum_mon = D * product[i].s_mon + sum_mon;
            break;
        }
    }
    printf("%.2lf", sum_mon);
    return 0;
}

B1020

原文:https://www.cnblogs.com/tsruixi/p/11767935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!