当前位置:网站首页>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;} 边栏推荐
- 微信小程序请求封装
- 2022.8.3
- php fails to write data to mysql
- Thinking and summary of the efficiency of IT R&D/development process specification
- Controller-----controller
- 8.4 Summary of the mock competition
- 线程之Happens-before规则
- Luogu: P2574 XOR的艺术 [线段树]
- 全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
- 深度学习21天——卷积神经网络(CNN):服装图像分类(第3天)
猜你喜欢

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

让程序员崩溃的N个瞬间(非程序员误入)

What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file

接口全周期的生产力利器Apifox

Creo 9.0 基准特征:基准轴

Concurrent CAS

周报2022-8-4

Dynamic memory development (C language)

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

Embedded practice ---- based on RT1170 transplant memtester to do SDRAM test (25)
随机推荐
“充钱”也难治快手的“亏亏亏”?
8.4 Summary of the mock competition
使用稀疏 4D 卷积对 3D LiDAR 数据中的运动对象进行后退分割(IROS 2022)
Code Audit - PHP
交换机端口的三种类型详解与hybrid端口实验
明天去订票,准备回家咯~~
XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
程序员的七种武器
工程制图知识点
eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
微信小程序请求封装
周报2022-8-4
【零基础玩转BLDC系列】无刷直流电机无位置传感器三段式启动法详细介绍及代码分享
The color of life divine
flink cdc支持从oracle dg库同步吗
How to make a puzzle in PS, self-study PS software photoshop2022, PS make a puzzle effect
There is only one switch, how to realize the nqa of master-slave automatic switching
让硬盘更快,让系统更稳定
百行代码发射红心,程序员何愁命不中女朋友!
【无标题】目录