pat 1070
2014-03-12 15:19
239 查看
1070. Mooncake (25)
时间限制 100 ms内存限制 32000 kB代码长度限制 16000 B判题程序 Standard作者 CHEN, YueMooncake 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.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;}[/code]
相关文章推荐
- python内置函数
- java的服务器空间
- 阿里校招之类实例化的顺序
- apply 判定变量类型
- SQL Trigger 判断增删改
- html 页面视图中的资源文件(css/js/image)的路径问题。
- JSON(04)PHP的JSON处理函数及将MySQL结果集快速转为JSON的方法
- java字符串的各种编码转换
- windows下常用软件
- How to install TSM Server and BA Client, Oracle TDP Client on Windows
- 用SSH压缩和解压zip,gz,.tar.gz等格式的正确方法
- CI项目配置文件
- html文字滚动代码 (转)
- Force “Internet Explorer 8” browser mode in intranet
- windows下常用软件
- c#处理3种json数据的实例
- 二叉树的宽度优先遍历(队列实现)
- 让UIWebView弹出键盘上的按钮显示中文
- js面向对象编程,定义接口
- 工具软件集合