1070 Mooncake (25 分)
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
分析:贪心水题。。
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-25-21.32.50
* Description : A1070
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
;
struct Node{
double amounts;
double sell;
double price;
}node[maxn];
bool cmp(Node a,Node b){
return a.price>b.price;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int n;
double d;
cin>>n>>d;
;i<n;i++){
cin>>node[i].amounts;
}
;i<n;i++){
cin>>node[i].sell;
node[i].price=node[i].sell/node[i].amounts;
}
sort(node,node+n,cmp);
double sum=0.0;
;i<n;i++){
if(node[i].amounts<d){
sum+=node[i].sell;
d-=node[i].amounts;
}
else{
sum+=node[i].price*d;
break;
}
}
printf("%.2f",sum);
;
}
1070 Mooncake (25 分)的更多相关文章
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT 1070. Mooncake (25)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- 1070. Mooncake (25)
题目如下: Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many ...
- PAT Advanced 1070 Mooncake (25) [贪⼼算法]
题目 Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many typ ...
- PAT (Advanced Level) 1070. Mooncake (25)
简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...
- PAT甲题题解-1070. Mooncake (25)-排序,大水题
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- A1070 Mooncake (25 分)
一.参考代码 #include<cstdio> #include<algorithm> #include<iostream> using namespace std ...
- PAT 1070 Mooncake[一般]
1070 Mooncake (25)(25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Aut ...
随机推荐
- 教你如何打开android4.3和4.4中隐藏的AppOps
注:下面的方法在4.4.2更新后已失效! PreferenceActivity的switchToHeaderInner()函数中会调用isValidFragment函数来检查fragment是否合法. ...
- <constant name="struts.devMode" value="false" />
在开发中,我们常常会遇到<constant name="struts.devMode" value="false" />,这是struts2的特性, ...
- BadUSB测试记录
0x00 前言 不是很新的东西,其他作者已对此做过研究测试,本文仅用来记录操作过程,保存日志,说明细节. 0x01参考资料 https://github.com/adamcaudill/Psychso ...
- TouchJSON的简单使用
TouchJSON是OC转换JSON的一个第三方类库,使用简单.在GitHub上可以轻松获取:TouchJSON 以下是简单的事例演示从douban movie请求JSON数据并转为字典对象后对控件赋 ...
- SWIFT用ScrollView加图片制作Banner
网上参考OBJC写的用ScrollView图片轮播效果,照着画了个,先上效果图: 附上代码: @IBOutlet weak var pc: UIPageControl! @IBOutlet weak ...
- Java中生产者与消费者模式
生产者消费者模式 首先来了解什么是生产者消费者模式.该模式也称有限缓冲问题(英语:Bounded-buffer problem),是一个多线程同步问题的经典案例.该问题描述了两个共享固定大小缓冲区的线 ...
- 图解SQL的inner join、left join、right join、full outer join、union、union all的区别【转载】
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codin ...
- cache和buffer区别
Cache: 一般用于读缓存,用于将频繁读取的内容放入缓存,下次在读取相同的内容,直接从缓存冲读取,提高读取性能,缓存可以有多级. Buffer:一般用于写缓存,用于解决不同介质直接存储速度的不同, ...
- 9.1 UDP协议
TCP 协议是面向连接的基于流的,可靠的传输服务.UDP是无连接的,基于数据报的,不可靠的传输服务,UDP没有粘包,但是会产生丢包. UDP模型如下: 可以看到,服务器端不用listen,也不用acc ...
- C++ 泛型 编写的 数据结构 栈
平时编程里经常需要用到数据结构,比如 栈和队列 等, 为了避免每次用到都需要重新编写的麻烦现将 C++ 编写的 数据结构 栈 记录下来,以备后用. 将 数据结构 栈 用头文件的形式 ...