当前位置:网站首页>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;} 边栏推荐
- Thinking and summary of the efficiency of IT R&D/development process specification
- There is only one switch, how to realize the nqa of master-slave automatic switching
- DPU — 功能特性 — 存储系统的硬件卸载
- The Secrets of the Six-Year Team Leader | The Eight Most Important Soft Skills of Programmers
- JS syntax usage
- 请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
- 网页直接访问链接不让安全中心拦截
- mySQL数据库初始化失败,有谁可以指导一下吗
- selectPage 动态改变参数方法
- eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
猜你喜欢
随机推荐
my journal link
按钮上显示值的轮流切换
2022-08-01 回顾基础二叉树以及操作
这样写有问题吗?怎么在sql-client 是可以做到数据的同步的
Comprehensively explain what is the essential difference between GET and POST requests?Turns out I always misunderstood
六年团队Leader实战秘诀|程序员最重要的八种软技能 - 脸皮薄容易耽误事 - 自我营销
深度学习21天——卷积神经网络(CNN):天气识别(第5天)
Spark cluster deployment (third bullet)
嵌入式实操----基于RT1170 移植memtester做SDRAM测试(二十五)
flink cdc支持从oracle dg库同步吗
Creo 9.0 基准特征:基准轴
leetcode refers to Offer 10- II. Frog jumping steps
如何实现按键的短按、长按检测?
CCVR基于分类器校准缓解异构联邦学习
C语言-数组
egg framework
tear apart loneliness
程序员的七种武器
PAT乙级-B1021 个位数统计(15)
Luogu P3368: 【模板】树状数组 2









