当前位置:网站首页>PAT Grade B-B1020 Mooncake(25)
PAT Grade B-B1020 Mooncake(25)
2022-08-05 09:13:00 【nekoha_dexter】
Mooncake is a traditional food eaten by Chinese during the Mid-Autumn Festival. There are many mooncakes with different flavors in different regions.Given the inventory of all types of mooncakes, the total selling price, and the maximum demand in the market, please calculate the maximum profit you can get.
Note: A portion of stock is allowed to be withdrawn at the time of sale.The situation given in the example is as follows: if we have 3 kinds of moon cakes, their inventory is 180,000 tons, 150,000 tons, and the total selling price is 7.5, 7.2, and 4.5 billion yuan respectively.If the maximum demand in the market is only 200,000 tons, then our maximum profit strategy should be to sell all 150,000 tons of the second type of moon cakes and 50,000 tons of the third type of moon cakes to obtain 72 + 45/2 = 9.45 billion (billion yuan).
input format:
Each input contains a test case.For each test case, a positive integer N not exceeding 1000 is given to represent the number of types of moon cakes, and a positive integer D not exceeding 500 (in 10,000 tons) represents the maximum market demand.The next line gives N positive numbers to indicate the inventory of each kind of moon cake (in 10,000 tons); the last line gives N positive numbers to indicate the total selling price of each kind of moon cake (in 100 million yuan).The numbers are separated by spaces.
Output format:
For each group of test cases, output the maximum profit in one line, in billions of yuan and accurate to 2 decimal places.
Input sample:
3 2018 15 1075 72 45Example output:
94.50#include#include#includeusing namespace std;struct stuff{ // cannot be named datafloat storage, total, price;} ;vector mooncake;//High unit price priority, same unit price and more stock prioritybool cmp(stuff a, stuff b){return a.price != b.price? a.price > b.price : a.storage > b.storage;}int main(){int n, d;//Type, demand, and all are positive integerscin >> n >> d;mooncake.resize(n);for(int i = 0; i < n; ++i)cin >> mooncake[i].storage;for(int i = 0; i < n; ++i){cin >> mooncake[i].total;mooncake[i].price = mooncake[i].total / mooncake[i].storage;}sort(mooncake.begin(), mooncake.end(), cmp);float ans = 0;for(int i = 0; i < n; ++i){// when inventory >= demand,if(mooncake[i].storage >= d){ans += mooncake[i].price * d;break;}ans += mooncake[i].total;d -= mooncake[i].storage;}printf("%.2f", ans);return 0;} 边栏推荐
猜你喜欢

复现一次循环和两次循环

工程制图试题

Weekly Report 2022-8-4

基于 Kubernetes 的微服务项目整体设计与实现

Concurrent CAS

ECCV 2022 Oral 视频实例分割新SOTA:SeqFormer&IDOL及CVPR 2022 视频实例分割竞赛冠军方案...

周报2022-8-4

Thinking and summary of the efficiency of IT R&D/development process specification

【Excel实战】--图表联动demo_001

Detailed explanation of DNS query principle
随机推荐
微信小程序请求封装
科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
thinkPHP5 realizes clicks (data increment/decrement)
openpyxl操作Excel文件
Hbuilder 学习使用中的一些记录
Xcode10的打包方式distribute app和启动项目报错以及Xcode 打包本地ipa包安装到手机上
routing----router
sql server中 两表查询 平均数 分组
k-nearest neighbor fault monitoring based on multi-block information extraction and Mahalanobis distance
Code Audit - PHP
【LeetCode】623. Add a row to the binary tree
Moonbeam团队发布针对整数截断漏洞的紧急安全修复
DPU — 功能特性 — 网络系统的硬件卸载
pytorch余弦退火学习率CosineAnnealingLR的使用
【LeetCode】623. 在二叉树中增加一行
What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file
Is there a problem with writing this?How to synchronize data in sql-client
基因数据平台
eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
2022.8.3