当前位置:网站首页>天梯赛--L2-003 月饼 (25 分)
天梯赛--L2-003 月饼 (25 分)
2022-04-22 14:16:00 【wowon~】
L2-003 月饼 (25 分)
月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。
注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45 亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 15 万吨第 2 种月饼、以及 5 万吨第 3 种月饼,获得 72 + 45/2 = 94.5(亿元)。
输入格式:
每个输入包含一个测试用例。每个测试用例先给出一个不超过 1000 的正整数 N 表示月饼的种类数、以及不超过 500(以万吨为单位)的正整数 D 表示市场最大需求量。随后一行给出 N 个正数表示每种月饼的库存量(以万吨为单位);最后一行给出 N 个正数表示每种月饼的总售价(以亿元为单位)。数字间以空格分隔。
输出格式:
对每组测试用例,在一行中输出最大收益,以亿元为单位并精确到小数点后 2 位。
输入样例:
3 20
18 15 10
75 72 45
输出样例:
94.50
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
double ku,sj;//库存,总售价;输入的库存与总售价并也可能是浮点数
double dj;//单价
bool operator<(const node &t)
{
return dj>t.dj;
}
}no[1010];
int main()
{
int n;
double m;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>no[i].ku;
for(int i=0;i<n;i++)
{
cin>>no[i].sj;
no[i].dj=(double)no[i].sj/no[i].ku;
}
sort(no,no+n);
double ans=0;
for(int i=0;i<n;i++)
{
if(m>=no[i].ku)
{
ans+=double(no[i].ku)*no[i].dj;
m-=no[i].ku;
}
else
{
ans+=(double)m*no[i].dj;
m-=m;
}
if(m<=0)break;
}
printf("%0.2lf\n",ans);
return 0;
}
版权声明
本文为[wowon~]所创,转载请带上原文链接,感谢
https://blog.csdn.net/with_wine/article/details/124342668
边栏推荐
- 【pytorch】自己实现精简版YOLOV3【五】,实现YOLOV3损失函数(一)
- uniapp运行到微信开发者工具中小程序端页面空白的解决办法
- Compared with redis, memcached
- Understand C language -- string, escape character, comment
- npm install --save 和 npm install --save-dev区别
- Lors de l'obtention d'une valeur dans la base de données, la base de données a une valeur, mais elle est vide.
- C语言的三子棋,用22天总结了一份完美的SQL学习笔记
- HashTable哈希表练习查找插入删除217、349 、202、287、290、532、205、128
- ipv6相关
- pip命令和在线、离线安装方法
猜你喜欢

图的遍历 深度优先DFS 广度优先BFS

Method of running uniapp to applet simulator - uniapp opens wechat developer tool preview support - hbuilderx

Methods of CRM system to improve customer experience

spark代码 spark-submit提交yarn-cluster模式

Multithreading primary

Byte beating interview sharing, in order to win this offer, who knows what I have experienced

Where do embedded software bugs come from and how do they go

Binarytree exercises constructing binary trees from traversal sequences of front order and middle order, middle order and back order | reconstructing binary trees 654, 105 and 106
![Error reported by uniapp to wechat developer tool - [wrong content of app.json file] JSON: the sitemap.json file corresponding to [](/img/3b/2f371eab7d2f9e976dcd4612a19518.png)
Error reported by uniapp to wechat developer tool - [wrong content of app.json file] JSON: the sitemap.json file corresponding to ["sitemaplocation"] was not found

3. fiddler证书安装和抓取hettps设置
随机推荐
C language sanziqi, summed up a perfect SQL learning note in 22 days
【论文笔记】Vision Transformers for Dense Prediction
移动端自适应与响应式布局
双指针头尾指针 167、|345、680、15、16、18、11、42
BitMap BloomFilter BitSet详解
Advanced multithreading
A solution to the problem of buying and selling stocks by force deduction
Compared with redis, memcached
Redis 批量删除数据(通配符)
Fastdfs installation and configuration
BinaryTree练习 从前序与中序、中序与后序遍历序列构造二叉树||重构二叉树654、105、106
QT create window flash back problem
二月份,我靠这一份PDF文档面试BAT,没想到竟然收到了5个offer
Understanding of redis
多线程初阶
985 official announcement: international ranking is no longer a construction goal!
awk命令
3. fiddler证书安装和抓取hettps设置
Thoughts on dealing with high concurrency problems
深入剖析阻塞队列BlockingQueue (详解ArrayBlockingQueue和LinkedBlockingQueue及其应用)