A1070. Mooncake (25)
2015-08-09 19:56
190 查看
1070. Mooncake (25)
时间限制100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
//如果题目没有说明是整数,就按小数处理
#include<cstdio> #include<algorithm> using namespace std; struct Mooncake{ double num,worth,price; }cake[1000]; bool cmp(Mooncake a,Mooncake b){ return a.price > b.price; } int main(){ int N; double D,sum = 0; scanf("%d %lf",&N,&D); for(int i = 0;i < N;i++){ //接收数量 scanf("%lf",&cake[i].num); } for(int i = 0;i < N;i++){ //接收总价值 scanf("%lf",&cake[i].worth); cake[i].price = cake[i].worth/cake[i].num; //计算单价 } sort(cake,cake+N,cmp); int i = 0; while(D){ while(i<N&&cake[i].num>0){ if(D>=cake[i].num){ sum += cake[i].worth; D -= cake[i].num; cake[i].num = 0; i++; } else{ sum += D*cake[i].price; D = 0; break; } } if(i>=N) break; } printf("%.2f\n",sum); return 0; }
相关文章推荐
- 背单词App开发日记6(终章总结)
- BZOJ 1057: [ZJOI2007]棋盘制作( dp + 悬线法 )
- 546A. Soldier and Bananas
- Candy
- whust #0.2 I Incognito
- hive 启动问题记录 及解决方法
- MATLAB out of memory深层次解决办法
- java面向接口编程
- 如何使用javascript做一个网页轮播图
- 装雷达
- iOS开发--Block
- 工厂方法模式
- 自适应图像分辨率
- 递归函数时间复杂度分析
- 循环获取所有控件
- C++对象模型——Virtual Member Functions (虚拟成员函数)(第四章)
- Android在onCreate()中获得控件尺寸
- 按单词逆序句子(含标点)
- Cmake使用教程
- OC中字符串NSstring