PAT甲级练习1070. Mooncake (25)
来源:互联网 发布:金蝶erp软件介绍 编辑:程序博客网 时间:2024/06/05 00:53
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 200180 150 1007.5 7.2 4.5Sample Output:
9.45
简单的贪心算法
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <string> #include <string.h> using namespace std;const int MAX = 1e3+10;int n, m;float x, y, tp=0.0;struct MC{float capacity;float prices;float sp;void read(){sp = prices / capacity;}}mc[MAX];bool cmp(MC a, MC b){ return a.sp > b.sp;}int main() {scanf("%d%d", &n, &m);for(int i=0; i<n; i++){scanf("%f", &x);mc[i].capacity = x;}for(int i=0; i<n; i++){scanf("%f", &x);mc[i].prices = x;mc[i].read();}sort(mc, mc+n, cmp);for(int i=0; i<n; i++){if(m==0) break;if(mc[i].capacity<=m){tp += mc[i].prices;m -= mc[i].capacity;}else{tp += (m * 1.0 / mc[i].capacity)*mc[i].prices;m = 0;}}printf("%.2lf", tp);scanf("%d",&n); return 0;}
- PAT甲级练习1070. Mooncake (25)
- PAT甲级1070. Mooncake (25)
- 1070. Mooncake (25)-PAT甲级
- 【PAT甲级】1070. Mooncake (25)
- PAT 甲级 1070. Mooncake (25)
- 1070. Mooncake (25)-PAT甲级真题
- 1020 月饼 PAT PAT乙级&&1070. Mooncake (25) PAT甲级
- pat甲级 10700---Mooncake
- 【PAT】1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- pat 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- PAT 1070. Mooncake (25)
- PAT (Advanced) 1070. Mooncake (25)
- PAT A 1070. Mooncake (25)
- ZJU-PAT 1070. Mooncake (25)
- PHP code
- PHP上传图片和视频 问题处理(初学者)
- C# 文件管理及文件的读写
- Linux查看硬件配置信息(Cpu、硬盘、内存)
- Android开发中数据的5种存储方式简介.txt
- PAT甲级练习1070. Mooncake (25)
- 【BZOJ 2141】排队【分块+Treap】
- 【模板】【数论】扩展欧几里得算法
- mysql之表复制
- iOS获取网络状态
- 蚂蚁分类信息系统 5.8 网上下载的免费版MYMPS蚂蚁分类信息系统 v5.8 GBK 插件安装后无法正常使用
- XML解析方式小谈
- C/C++函数参数为何是从右到左?
- Spring Bean的作用域测试