Alice's mooncake shopTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4817 Accepted Submission(s): 1300 Problem Description The Mid-Autumn Festival, also known as the Moon Festival or Zhongqiu Festival is a popular harvest festival celebrated by Chinese people, dating back over 3,000 years to moon worship in China's Shang Dynasty. The Zhongqiu Festival is held on the 15th day of the eighth month in the Chinese calendar, which is in September or early October in the Gregorian calendar. It is a date that parallels the autumnal equinox of the solar calendar, when the moon is at its fullest and roundest.
Input The input contains no more than 10 test cases.
Output You should output one line for each test case: the minimum cost.
Sample Input 1 10 Jan 1 2000 9 10 5 2 20 20 20 10 10 8 7 9 5 10 0 0
Sample Output 70 | ||
题意:Alice开了家月饼店,现有2500笔订单,订单包括某小时(2000年1月1日0点算第1个小时的开始)和需要的月饼数量。然后给你前100000小时的信息,包括第i个小时做1个饼的花费cost[i]。然后给你月饼的保质期T(说明订单i只能买[order[i].hour-T ,order[i].hour ]
这个区间生产的饼)和保存1小时的花费S,让你求最小的花费满足所有订单。
题解:
首先要把订单的时间转化成自2000年1月1日0点开始的第几小时,由于最多100000小时,所以最大到2012年的样子。然后维护一个最小值的单调队列。就是把天数转化为时间这个方法可以学习
具体实现:
首先我们已经获得第一个Order的单调队列,记为LQ,然后是处理第2个订单,我们把LQ分成2个部分。A:下标在order[2].hour-T, order[1].hour
范围(A集合可能为空) B:下标在order[1].hour , order[2].hour
的范围。对于A,由于第2个订单也可能使用到A集合里面的元素,所以我们要先对A集合所有元素加上1.2订单时间差的花费S*(order[2].hour- order[1].hour)
(用于保存),然后再把B集合的元素加到单调队列里面,最后队列头的值即为第2个订单得到一个饼的最小花费,乘以订单数即可。之后的每个订单同样处理即可。注意,答案要long long
。代码解释写的也都很详细了。
代码:
/*
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 佛祖保佑 永无BUG
#include<bits/stdc++.h>
#define LL long long
#define N 2505
#define M 100005
using namespace std;
int n,m,d,y,h,num,k,T,S;
int Date[15]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},a[M],pos[M],sum[M];
string Mon[15]={"","Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" , "Dec"};
string s;
LL ans;
struct ljh
{
int t,ned;
//需要到的第几个小时,需要的量
ljh(){};
ljh(int tt,int need)
{
t=tt;
ned=need;
}
bool operator < (const ljh& b)const
{
return t>b.t;
}
};
int main()
{
while(scanf("%d%d",&n,&m)&&n!=0&&m!=0)
{
ans=0;
priority_queue<ljh>q;
while(!q.empty())q.pop();
deque< pair<int,int> >Q;//STL双端队列
while(!Q.empty())Q.pop_back();
for(int i=1;i<=n;i++)
{
cin>>s;
scanf("%d%d%d%d",&d,&y,&h,&num);
for(int j=2000;j<y;j++)
if((j%4==0&&j%100!=0)||j%400==0)d+=366;
else d+=365;//之前有某一年是闰年
for(int j=1;j<=12;j++)
if(Mon[j]==s)
{
k=j;
break;
}
for(int j=1;j<k;j++)
if(j==2&&((y%4==0&&y%100!=0)||y%400==0))d+=29;
//计算该年之前月份的天数,该年是否是闰年
else d+=Date[j];
d--;//因为我本身那一天并没有过满,并且已经有了当天的第几点,所以需要减去本身那一天
q.push(ljh(d*24+h,num));
}
scanf("%d%d",&T,&S);
//保存的时间价格
for(int i=0;i<m;i++)
//题目说的是第几个小时,而我之前的n个需求是第几点的,换算成第i点的价格
{
int x;
scanf("%d",&x);
while(!Q.empty()&&x<=Q.back().first+(i-Q.back().second)*S)
Q.pop_back();
//现在做一个价格相对于之前做了放几个小时的价格比较
Q.push_back(make_pair(x,i));
// ljh now=q.top();
while(!q.empty()&&q.top().t==i)
{
while(!Q.empty()&&i-Q.front().second>T)Q.pop_front();
//现在的时间减去之前做的时间,看是否过期了
ans+=(Q.front().first+(i-Q.front().second)*S)*q.top().ned;
//(做的时候的价格+(存放的时间)*存放价格)*需求的量
q.pop();//可能有多个需求在同一时间
}
}
printf("%lld\n",ans);
}
return 0;
}