当前位置:网站首页>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 45
Example 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;}
边栏推荐
- Chapter 12 Bayesian Networks
- SQL语句查询字段内重复内容,并按重复次数加序号
- CCVR eases heterogeneous federated learning based on classifier calibration
- Luogu: P2574 XOR的艺术 [线段树]
- tensorflow.keras无法引入layers
- Xcode 12 ld: symbol(s) not found for architecture armv64
- sphinx matches the specified field
- Overall design and implementation of Kubernetes-based microservice project
- C语言-数组
- Creo 9.0 基准特征:基准坐标系
猜你喜欢
干货!生成模型的评价与诊断
Detailed explanation of DNS query principle
基因数据平台
苹果官网商店新上架Mophie系列Powerstation Pro、GaN充电头等产品
Comprehensively explain what is the essential difference between GET and POST requests?Turns out I always misunderstood
工程制图试题
ECCV 2022 Oral 视频实例分割新SOTA:SeqFormer&IDOL及CVPR 2022 视频实例分割竞赛冠军方案...
Why is pnpm hitting npm and yarn dimensionality reduction?
mySQL数据库初始化失败,有谁可以指导一下吗
代码审计—PHP
随机推荐
routing----router
施一公:科学需要想象,想象来自阅读
(转)[Json]net.sf.json 和org.json 的差别及用法
seata源码解析:TM RM 客户端的初始化过程
How to replace colors in ps, self-study ps software photoshop2022, replace one color of a picture in ps with another color
网页直接访问链接不让安全中心拦截
2022.8.3
XSS靶机通关以及XSS介绍
HStreamDB Newsletter 2022-07|分区模型优化、数据集成框架进一步完善
Spark cluster deployment (third bullet)
按钮上显示值的轮流切换
leetcode refers to Offer 10- II. Frog jumping steps
Chapter 12 Bayesian Networks
tear apart loneliness
Hbuilder 学习使用中的一些记录
ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...
CCVR eases heterogeneous federated learning based on classifier calibration
The difference between beautiful MM and ordinary MM
SQL语句查询字段内重复内容,并按重复次数加序号
express hot-reload