码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 4122 Alice's mooncake shop

时间:2016-03-13 22:26:22      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4122

题意大意是Alice开着一家月饼店,可以接到n做月饼的订单,而Alice只有在从2000年一月一日0点为第一个小时开始的前m个小时内做月饼,而且只能在整点

的时候做月饼,并且做月饼不花费时间,也就是一瞬间就可以做超级多的月饼,而每个月饼有t个小时的保质期,每个月饼保存每小时需要花费s元,而在可以

做月饼的m小时内,不同小时做月饼花费的钱也不同,每个订单都有交付订单嗯达时间,某年某月某日某时交付该订单所要求的r个月饼,求完成所有订单所

花费的最少的钱的数目。

细想一下,把时间统一成从起点时间开始的小时数,可以看成在一条时间轴上,n个订单就是n个特定结点,就是要找出每个结点前t个时间点内最小的花费

与单调队列类似,比较范围内最小的单个月饼的花费,由于这个花费除了本身的价格还与距离订单时间的时间长短有关,因为保存月饼还要花费,而且与

保存的时间越长花费越多,所以队列里要存储两个变量,价格和时间。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<queue>
 5 using namespace std;
 6 typedef long long ll;
 7 
 8 typedef struct  point{
 9      ll need,time;
10 };
11 
12 deque<point>q;
13 queue<point>p;
14 char yj[10];
15 int num[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
16 
17 int run(ll x){
18       if ((x%4==0&&x%100!=0)||x%400==0) return 0;
19       else return 1;
20 }
21 
22 ll _moon(){
23     if (strcmp(yj,"Jan")==0) return 1;
24     else if (strcmp(yj,"Feb")==0) return 2;
25     else if (strcmp(yj,"Mar")==0) return 3;
26     else if (strcmp(yj,"Apr")==0) return 4;
27     else if (strcmp(yj,"May")==0) return 5;
28     else if (strcmp(yj,"Jun")==0) return 6;
29     else if (strcmp(yj,"Jul")==0) return 7;
30     else if (strcmp(yj,"Aug")==0) return 8;
31     else if (strcmp(yj,"Sep")==0) return 9;
32     else if (strcmp(yj,"Oct")==0) return 10;
33     else if (strcmp(yj,"Nov")==0) return 11;
34     else return 12;
35 }
36 
37 ll _time(){
38     ll a,b,c,i;
39     scanf("%s %I64d %I64d %I64d",yj,&a,&b,&c);
40     ll d=_moon(),h=0;
41     for (i=2000;i<b;i++){
42         if (run(i)) h+=365*24;
43         else h+=366*24;
44     }
45     for (i=1;i<d;i++){
46         if (i==2&&!run(b)) h+=29*24;
47         else h+=num[i]*24;
48     }
49     h+=(a-1)*24;
50     return h+c;
51 }
52 
53 int main()
54 {
55     ll n,m,i,t,s,x;
56     point s1;
57     while (~scanf("%I64d %I64d",&n,&m),n+m){
58         q.clear();
59         for (i=1;i<=n;i++){
60             s1.time=_time();
61             scanf("%I64d",&s1.need);
62             p.push(s1);
63         }
64         /*for (i=1;i<=n;i++){
65         printf("%I64d %I64d\n",p.front().need,p.front().time);
66         p.pop();
67         }*/
68         scanf("%I64d %I64d",&t,&s);
69         ll ans=0;
70         for (i=0;i<m;i++){
71             scanf("%I64d",&x);
72             while (!q.empty()&&x<=q.back().need+(i-q.back().time)*s)
73                q.pop_back();
74             s1.need=x;s1.time=i;
75             q.push_back(s1);
76             while (!p.empty()&&i==p.front().time){
77                 while (!q.empty()&&i>q.front().time+t)
78                     q.pop_front();
79                 ans+=((i-q.front().time)*s+q.front().need)*p.front().need;
80                 p.pop();
81             }
82         }
83         printf("%I64d\n",ans);
84     }
85     return 0;
86 }

 

hdu 4122 Alice's mooncake shop

标签:

原文地址:http://www.cnblogs.com/JJCHEHEDA/p/5273270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!