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 ...
随机推荐
- L233
Betty was offended because she felt that her friends had ignored her purposefully(deliberately) at t ...
- mysql-connector-java-3.1.10-bin-g.jar 和 mysql-connector-java-3.1.10-bin.jar两个文件有什么不同呀?
MySQL Connector/J的文档里说: MySQL Connector/J is distributed as a .zip or .tar.gz archive containing the ...
- Python range
i = 1 while i <= 100: print(i) i += 1 # range(参数) [0,参数) 取不到 for i in range(10): # range() 可以被迭代 ...
- 《流畅的python》读书笔记
流畅的python 第1章 python数据模型 ---1.1 一摞Python风格的纸牌 特殊方法,即__method__,又被称为魔术方法(magic method)或者双下方法(dunder-m ...
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程
Himi 原创, 欢迎转载,转载请在明显处注明! 谢谢. 原文地址:http://blog.csdn.net/xiaominghimi/article/details/6937097 //——201 ...
- delphi批量存入多媒体字段 遇到内存溢出的坑
最近delphi做一个小工具其中一个需求要把上W张照片存入数据库多媒体字段. 程序转到1,2W的时候即内在溢出了.最多一次转了3W张照片.很简单的一段代码后来仔细检查发现其中的坑. 下面放上代码 wi ...
- 关于self和super在oc中的疑惑与分析 (self= [super init])
这个问题貌似很初级,但很容易让人忽略,me too .直到在一次面试时被问到,稀里糊涂的回答了下.实在惭愧, 面试一定都是很注重 基础的,不管高级还是初级. 虽然基础好跟基础不好都可以写代码,网上那么 ...
- test20181006 投票
题意 分析 考场30分 枚举大小为k的子集的算法终于用上了. 时间复杂度 \[O\left(\binom{n}{k} \cdot \binom {k}{\frac{k}{2}} \cdot k\rig ...
- APP自动化测试各项指标分析
一.内存分析专项 启动App. DDMS->update heap 操作app,点几次GC dump heap hprof-conv转化 MAT分析 二.区分几种内存 VSS- Virtual ...
- [CLPR] 卷积还是相关? - Opencv之filter2D探究
I am doing something about convolving images in Python and for sake of speed I chose opencv 2.4.9. O ...