【1070】Mooncake (25 分)
【摘要】
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<algorithm> #include<map>#inclu...
-
#include<iostream>
-
#include<stdio.h>
-
#include<stdlib.h>
-
#include<math.h>
-
#include<string.h>
-
#include<algorithm>
-
#include<map>
-
#include<vector>
-
#include<queue>
-
using namespace std;
-
//key:策略-总是选择单价最高的月饼售出,可以获得最大的利润
-
struct mooncake{
-
double store; //库存量
-
double sell; //总售价
-
double price; //单价
-
}cake[1010];
-
bool cmp(mooncake a,mooncake b){ //按单价从高到低排序
-
return a.price > b.price;
-
}
-
int main(){
-
int n;
-
double D;
-
scanf("%d%lf",&n,&D);
-
for(int i=0;i<n;i++){
-
scanf("%lf",&cake[i].store); //库存
-
}
-
for(int i=0;i<n;i++){
-
scanf("%lf",&cake[i].sell); //每种月饼的总售价
-
cake[i].price=cake[i].sell / cake[i].store; //计算单价
-
}
-
sort(cake,cake+n,cmp); //单价从高到低进行排序
-
double ans=0; //收益
-
for(int i=0;i<n;i++){
-
if(cake[i].store <=D){ //如果需求量大于月饼库存量
-
D -= cake[i].store; //第i种月饼全部卖出
-
ans += cake[i].sell;
-
}else{ //如果月饼库存量高于需求量
-
ans += cake[i].price*D; //只卖出剩余需求量的月饼
-
break;
-
}
-
}
-
printf("%.2f\n",ans);
-
system("pause");
-
return 0;
-
}
文章来源: andyguo.blog.csdn.net,作者:山顶夕景,版权归原作者所有,如需转载,请联系作者。
原文链接:andyguo.blog.csdn.net/article/details/99696709
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)