PAT1070. Mooncake

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
思路:此题需要记住 库存容量也可能是浮点数。题中会以此来设置陷阱。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 using namespace std;
 5 struct Mooncake
 6 {
 7     double storage;
 8     double money;
 9     double xing;
10 }Mooncake[1010];
11 bool cmp(struct Mooncake a,struct Mooncake b)
12 {
13     return a.xing>b.xing;
14 }
15 int main(int argc, char *argv[])
16 {
17     int N;
18     double need;    //需要将 need 和存储容量就设为double 型。
19     scanf("%d%lf",&N,&need);
20     for(int i=0;i<N;i++)
21     {
22         scanf("%lf",&Mooncake[i].storage);
23     }
24     for(int i=0;i<N;i++)
25     {
26         scanf("%lf",&Mooncake[i].money);
27         Mooncake[i].xing=Mooncake[i].money/Mooncake[i].storage;
28     }
29     sort(Mooncake,Mooncake+N,cmp);
30     double profit=0;
31     for(int i=0;i<N;i++)
32     {
33         if(Mooncake[i].storage<=need)
34         {
35             need-=Mooncake[i].storage;
36             profit+=Mooncake[i].money;
37             if(need==0)
38               break;
39         }
40         else
41         {
42             profit+=Mooncake[i].xing*need;
43             break;
44         }
45     }
46     printf("%.2f",profit);
47     return 0;
48 }

时间: 2024-08-25 15:13:31

PAT1070. Mooncake的相关文章

pat1070. Mooncake (25)

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 a

hdu 4122 Alice&#39;s mooncake shop

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4122 题意大意是Alice开着一家月饼店,可以接到n做月饼的订单,而Alice只有在从2000年一月一日0点为第一个小时开始的前m个小时内做月饼,而且只能在整点 的时候做月饼,并且做月饼不花费时间,也就是一瞬间就可以做超级多的月饼,而每个月饼有t个小时的保质期,每个月饼保存每小时需要花费s元,而在可以 做月饼的m小时内,不同小时做月饼花费的钱也不同,每个订单都有交付订单嗯达时间,某年某月某日某时交付该

HDU 4122 Alice&#39;s mooncake shop 单调队列优化dp

Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4122 Description The Mid-Autumn Festival, also known as the Moon Festival or Zhongqiu Festival is a popular harvest festival celebrated by Ch

HDU 4122 Alice&#39;s mooncake shop --RMQ

题意: 一个月饼店做月饼,总营业时间m小时,只能在整点做月饼,可以做无限个,不过在不同的时间做月饼的话每个月饼的花费是不一样的,假设即为cost[i],再给n个订单,即为在某个时间要多少个月饼,时间从2000年1月1日0时开始计算,必须在每个订单的时间之前完成这么多月饼,月饼还有保质期T小时以及保存费用S每小时,现在问满足这n个点的最小成本是多少. 解法: 因为月饼有保质期T,所以第i个月饼只能在[Ti-T+1,Ti]时间内做好.如果时间j有订单,假设在时间i做月饼是最好的,那么这个订单每个月饼

PAT 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 al

【HDOJ】4122 Alice&#39;s mooncake shop

RMQ的基础题目,简单题. 1 /* 4122 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector> 10 #include <deque>

hdu4122 Alice&#39;s mooncake shop 单调队列

http://acm.hdu.edu.cn/showproblem.php?pid=4122 Alice's mooncake shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2908    Accepted Submission(s): 744 Problem Description The Mid-Autumn Festi

hdu 4122 Alice&amp;#39;s mooncake shop (线段树)

题目大意: 一个月饼店每一个小时做出月饼的花费不一样. 储存起来要钱.最多存多久.问你把全部订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ) 整理一下会发现式子就是 cost[]-j*s + i*s 对于每个订单,我们把i拿出来分析 所以也就用cost - j*s 建树. 然后在储存期间找到最小的花费即可了. #include <cstdio> #include <iostream> #include <algo

从global到mooncake迁移SQL Azure

之前遇到了问题,在此备注一下: 因为两个环境基本上可以认为是隔离的,所以迁移过程基本上只有通过导出.导入的方式(也是官方推荐的方式): 1.从global上进行数据库的export操作(扩展名bacpac),导出到blob中.通过Azure管理界面完成(当然也可以通过azure命令行,不过操作比较简单就用界面了) 2.从global的blob中将文件复制到mooncake的blob中.可以手动下载.上传,如果文件很大的话,也可以通过AzCopy命令行实现服务器端的点对点复制. 3.在moonca