加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

【PAT】B1020 月饼 (25)(25 分)

发布时间:2020-12-14 03:49:30 所属栏目:大数据 来源:网络整理
导读:#includestdio.h#includealgorithmusing namespace std;const int maxn = 1000;typedef struct yuebing { double cun; double shouyi; double danjian;}yue;yue arr[maxn];bool cmp(yue a,yue b) { return a.danjianb.danjian;}int main(){ int N,D; double
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn = 1000;
typedef struct yuebing {
    double cun;
    double shouyi;
    double danjian;
}yue;
yue arr[maxn];
bool cmp(yue a,yue b) {
    return a.danjian>b.danjian;
}
int main()
{
    int N,D; double shoushou = 0;
    scanf("%d%d",&N,&D);
    //输入库存
    for (int i = 0; i<N; i++) {
        scanf("%lf",&arr[i].cun);
    }
    //输入收益,并计算单收益
    for (int i = 0; i<N; i++) {
        scanf("%lf",&arr[i].shouyi);
        arr[i].danjian = arr[i].shouyi / arr[i].cun;
    }
    sort(arr,arr + N,cmp);//根据但收益排序
    for (int i = 0; i<N; i++) {
        if (arr[i].cun >= D) {
            shoushou += arr[i].danjian*D;
            break;
        }
        if (arr[i].cun<D)
            shoushou += arr[i].shouyi;
        D -= arr[i].cun;
    }
    printf("%.2f",shoushou);
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读