标签:hdu
http://acm.hdu.edu.cn/showproblem.php?pid=4122

1 10 Jan 1 2000 9 10 5 2 20 20 20 10 10 8 7 9 5 10 0 0
70Hint“Jan 1 2000 9 10” means in Jan 1st 2000 at 9 o‘clock , there‘s a consumer ordering 10 mooncakes. Maybe you should use 64-bit signed integers. The answer will fit into a 64-bit signed integer.
题意:一个月饼店只在整点工作。在整点可以制作任意多个月饼。但是在不同的时间制作月饼花费的代价不一样。而且如果一个月饼做好后储存。每小时将花费S。但是储存时间不超过T。现在给你该店工作的最长时间m。和n个订单。问你完成订单的最小花费。
思路:很简单的单调队列,把日期处理成小时后,用单调队列维护下最小值就好,队列头加入新的时间点的,队列尾删除过期的。注意会有相同时间点的订单。
/**
* @author neko01
*/
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-8;
const double pi=acos(-1.0);
const int INF=0x7fffffff;
const LL inf=(((LL)1)<<61)+5;
char s[12][5]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct node{
int h,r;
}a[2555];
bool check(int y)
{
return ((y%4==0&&y%100!=0)||y%400==0);
}
int input()
{
char str[5];
int d,y,h;
scanf("%s%d%d%d",str,&d,&y,&h);
int t=0,tmp=0,m=1;
for(int i=2000;i<y;i++)
{
if(check(i)) t+=24*366;
else t+=24*365;
}
if(check(y)) day[1]=29;
else day[1]=28;
for(int i=0;i<12;i++)
{
if(strcmp(s[i],str)==0)
{
m=i+1;
break;
}
tmp+=day[i];
}
t=t+(tmp+d-1)*24+h+1;
return t;
}
int q[111111];
int p[111111];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
if(n==0&&m==0) break;
for(int i=0;i<n;i++)
{
a[i].h=input();
scanf("%d",&a[i].r);
// printf("%d\n",a[i].h);
}
int t,s;
scanf("%d%d",&t,&s);
int front=0,rear=0,j=0;
LL ans=0;
for(int i=1;i<=m;i++)
{
scanf("%d",&p[i]);
while(front<rear&&p[i]<=p[q[rear-1]]+(i-q[rear-1])*s)
rear--;
q[rear++]=i;
while(j<n&&i==a[j].h)
{
while(q[front]+t<a[j].h) front++; //过期
ans+=a[j].r*(p[q[front]]+(i-q[front])*s);
j++;
}
}
printf("%I64d\n",ans);
}
return 0;
}
hdu4122 Alice's mooncake shop 单调队列
标签:hdu
原文地址:http://blog.csdn.net/neko01/article/details/40867385