当前位置: 首页 > news >正文

PAT A1070 Mooncake

1070 Mooncake

分数 25

作者 CHEN, Yue

单位 浙江大学

Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region's culture. Now given the inventory amounts and the prices of all kinds of the mooncakes, together with the maximum total demand of the market, you are supposed to tell the maximum profit that can be made.

Note: partial inventory storage can be taken. The sample shows the following situation: given three kinds of mooncakes with inventory amounts being 180, 150, and 100 thousand tons, and the prices being 7.5, 7.2, and 4.5 billion yuans. If the market demand can be at most 200 thousand tons, the best we can do is to sell 150 thousand tons of the second kind of mooncake, and 50 thousand tons of the third kind. Hence the total profit is 7.2 + 4.5/2 = 9.45 (billion yuans).

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers N (≤1000), the number of different kinds of mooncakes, and D (≤500 thousand tons), the maximum total demand of the market. Then the second line gives the positive inventory amounts (in thousand tons), and the third line gives the positive prices (in billion yuans) of N kinds of mooncakes. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the maximum profit (in billion yuans) in one line, accurate up to 2 decimal places.

Sample Input:

3 200
180 150 100
7.5 7.2 4.5

Sample Output:

9.45

 将每种月饼的信息用一个结构体存储,包括储量,总价值,单价,然后以单价递减的顺序
 * 排序,当单价越高时,卖出去的月饼利润越高;

/*** 将每种月饼的信息用一个结构体存储,包括储量,总价值,单价,然后以单价递减的顺序* 排序,当单价越高时,卖出去的月饼利润越高;
*/#include <iostream>
#include <algorithm>using namespace std;struct Mooncake
{double sto, val, pri;bool operator < (const Mooncake & a) const{return pri > a.pri;}
};const int N = 1e4+10;
struct Mooncake moon[N];int main()
{int n, dem;cin >> n >> dem;for(int i=0; i<n; ++i)cin >> moon[i].sto;for(int i=0; i<n; ++i){cin >> moon[i].val;moon[i].pri = moon[i].val / moon[i].sto;}double pro = 0;sort(moon, moon + n);for(int i=0; i<n && dem; ++i){if(dem >= moon[i].sto){pro += moon[i].val;dem -= moon[i].sto;}else{pro += dem * moon[i].pri;dem = 0;}}printf("%.2f\n", pro);return 0;
}

http://www.lryc.cn/news/90178.html

相关文章:

  • MyBatis- plus
  • Java --- 期末复习卷
  • File类与IO流相关面试知识(一)
  • 009 - STM32学习笔记 - 中断
  • 分享几种js格式化金额的方法
  • 圣墟传说H5手工端搭建架设教程
  • 编程(40)----------单例模式
  • Java开发 - 让你少走弯路的Redis主从实现单节点哨兵模式
  • Java的Atomic原子类
  • 离线语音控制新方案,NRK3303语音识别芯片在智能风扇的应用
  • 在树莓派3B+上安装Pytorch1.7
  • Java性能权威指南-总结4
  • c语言全局变量和局部变量问题汇总
  • 14.3:给定一个由字符串组成的数组strs,必须把所有的字符串拼接起来,返回所有可能的拼接结果中字典序最小的结果
  • C++ 项目实战:跨平台的文件与视频压缩解压工具的设计与实现
  • C和指针(二)数据
  • PyTorch基础学习(一)
  • chatgpt赋能python:Python代做:让您的网站更友好的SEO利器
  • 2022年都快结束了,还有人不会安卓录屏?在安卓上录制屏幕的的实现方式
  • px rem em rpx 区别 用法
  • 忆享聚焦|ChatGPT、AI、网络数字、游戏……近期热点资讯一览
  • [Daimayuan] 树(C++,动态规划,01背包方案数)
  • 如何选择源代码加密软件
  • TO-B类软件产品差异化
  • 设计模式之美-实战一(上):业务开发常用的基于贫血模型的MVC架构违背OOP吗?
  • ChatGPT如何训练自己的模型
  • springboot使用线程池的实际应用(一)
  • ESP-8266学习笔记
  • Java泛型简单的使用
  • 深度探索:Qt CMake工程编译后的自动打包策略