当前位置:网站首页>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;} 边栏推荐
- DPU — 功能特性 — 网络系统的硬件卸载
- 交换机端口的三种类型详解与hybrid端口实验
- Hbuilder 学习使用中的一些记录
- DPU — 功能特性 — 存储系统的硬件卸载
- 阿里云存储的数据库是怎么自动加快加载速度的呢www.cxsdkt.cn怎么设置案例?
- 使用 External Secrets Operator 安全管理 Kubernetes Secrets
- tensorflow.keras无法引入layers
- MySQL database error The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
- Walk 100 trick society
- 【零基础玩转BLDC系列】无刷直流电机无位置传感器三段式启动法详细介绍及代码分享
猜你喜欢
随机推荐
Overall design and implementation of Kubernetes-based microservice project
Is there a problem with writing this?How to synchronize data in sql-client
The difference between beautiful MM and ordinary MM
今天是元宵节~~
Concurrent CAS
Excuse me, guys, is it impossible to synchronize two databases in real time using Flink SQL CDC?
嵌入式实操----基于RT1170 移植memtester做SDRAM测试(二十五)
XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
CROS and JSONP configuration
C语言-数组
Luogu P1966: [NOIP2013 提高组] 火柴排队 [树状数组+逆序对]
ts/js function pass parameter with function writing
How to make pictures clear in ps, self-study ps software photoshop2022, simple and fast use ps to make photos clearer and more textured
CCVR eases heterogeneous federated learning based on classifier calibration
按钮上显示值的轮流切换
Thinking after writing a code with a very high CPU usage
ts/js 函数传参带函数写法
Controller-----controller
只有一台交换机,如何实现主从自动切换之nqa
好资料汇总









