pat 1070
来源:互联网 发布:双色球红球最简单算法 编辑:程序博客网 时间:2024/05/01 10:48
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 <stdio.h>#include <algorithm>using namespace std;struct Price{double pce;int id;} price[1010];int n;double d;double tons[1010];bool cmp(Price a, Price b){return a.pce > b.pce;}int main(){int i, j;while(scanf("%d%lf", &n, &d) != EOF){for(i = 1; i <= n; i++){scanf("%lf", &tons[i]);}for(i = 1; i <= n; i++){scanf("%lf", &price[i].pce);price[i].id = i;}for(i = 1; i <= n; i++)price[i].pce = price[i].pce / tons[i];double sum = 0;int index = 1;sort(price + 1, price + n + 1, cmp);while(d > 0 && index <= n){double max = 0;int cnt = price[index].id;if(tons[cnt] < d){sum = sum + price[index].pce * tons[cnt];d = d - tons[cnt];}else{sum = sum + price[index].pce * d;d = 0;}index++;}printf("%.2lf\n", sum);}return 0;}
- pat 1070
- PAT 1070
- pat 1070Mooncake (25)
- PAT(甲级)1070
- PAT甲级1070
- PAT乙级1070
- PAT 1070 Mooncake
- PAT 1070结绳
- PAT basic 1070
- 结绳(PAT-1070)
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- word2013 论文引用参考文献
- 关于签名后的apk的优化
- 阿里校招之类实例化的顺序
- 免费的文本编辑器 (copied)
- 点跟多边形的碰撞检测
- pat 1070
- PHP中Imagick类的使用
- ARM处理器模式弹跳机制的初始化 笔记版 转载请注明出处---crosskernel@gmail.com
- windows 输出\r\n问题
- 算法概率思维导图
- C# 模拟键盘输入
- cmd 中报错:不是内部或外部命令,也不是可运行的程序
- LDA学习l
- loadlibrary 返回错误126 找不到指定的模块