hdu4122 hdoj4122

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. 

The traditional food of this festival is the mooncake. Chinese family members and friends will gather to admire the bright mid-autumn harvest moon, and eat mooncakes under the moon together. In Chinese, “round”(圆) also means something like “faultless” or “reuion”, so the roundest moon, and the round mooncakes make the Zhongqiu Festival a day of family reunion.

Alice has opened up a 24-hour mooncake shop. She always gets a lot of orders. Only when the time is K o’clock sharp( K = 0,1,2 …. 23) she can make mooncakes, and We assume that making cakes takes no time. Due to the fluctuation of the price of the ingredients, the cost of a mooncake varies from hour to hour. She can make mooncakes when the order comes,or she can make mooncakes earlier than needed and store them in a fridge. The cost to store a mooncake for an hour is S and the storage life of a mooncake is T hours. She now asks you for help to work out a plan to minimize the cost to fulfill the orders.
 

Input
The input contains no more than 10 test cases. 
For each test case:
The first line includes two integers N and M. N is the total number of orders. M is the number of hours the shop opens. 
The next N lines describe all the orders. Each line is in the following format:

month date year H R

It means that on a certain date, a customer orders R mooncakes at H o’clock. “month” is in the format of abbreviation, so it could be "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" or "Dec". H and R are all integers. 
All the orders are sorted by the time in increasing order. 
The next line contains T and S meaning that the storage life of a mooncake is T hours and the cost to store a mooncake for an hour is S.
Finally, M lines follow. Among those M lines, the i th line( i starts from 1) contains a integer indicating the cost to make a mooncake during the i th hour . The cost is no more than 10000. Jan 1st 2000 0 o'clock belongs to the 1 st hour, Jan 1st 2000 1 o'clock belongs to the 2 nd hour, …… and so on.

(0
The input ends with N = 0 and M = 0.
 

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
Hint
“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.
 



题意:
第一行给你有多少个人要买(n)和商店开放时间(即可做月饼的时间,m个小时,每小时都能做月饼!但只能在整点做月饼)
下面n行给你来买的人的日期(月,日,年,小时)和要多少个月饼!(商店在2000 Jan 1st 0 o'clock开放)
再下面一行是两个数据,S和T,S是做好的月饼可以保存的时间,T是每个月饼每保存一小时需要花费的钱
然后跟着m行,分别表示第i小时(m>=i>=1)做一个月饼所花费的钱
这里有个关键的地方:
可以在买的人到来前就做好月饼,然后直接给他,也可以现场做现场卖,做月饼是不用时间的。
输出花费的 最少 的钱!

分析:
刚开始想用贪心直接下去,但是可能月饼无法保存到买的人到来,也有可能是之前做的月饼保存后给买的人更省钱,有很多情况考虑。
但是这题我们看问题只要输出花费的 最少 的钱
可以想到用 单调队列 来维护 最小值

code:
#include 
#include 
struct s{
	int time,num;//time是买月饼人到的时间,num是买的个数
}order[2505];//买月饼人的信息
struct p{
	int wastetime,t;//wastetime是现在这个整点做月饼的花费,t是当前时间
}yueb[2505];//做月饼的信息
int months[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};//非闰月和闰月
int leapyear(int year)
{
	return year%4==0&&year%100!=0||year%400==0;
}//判断闰年
int month(char *s)
{
	if(strcmp(s,"Jan")==0)
		return 1;		
	if(strcmp(s,"Feb")==0)
		return 2;
	if(strcmp(s,"Mar")==0)
		return 3;
	if(strcmp(s,"Apr")==0)
		return 4;
	if(strcmp(s,"May")==0)
		return 5;
	if(strcmp(s,"Jun")==0)
		return 6;
	if(strcmp(s,"Jul")==0)
		return 7;
	if(strcmp(s,"Aug")==0)
		return 8;
	if(strcmp(s,"Sep")==0)
		return 9;
	if(strcmp(s,"Oct")==0)
		return 10;
	if(strcmp(s,"Nov")==0)
		return 11;
	return 12;
}//判断在哪个月
int gettime(int m,int d,int y,int h)
{
	int i,t=0;
	for(i=2000;i=x)//如果队列头指针小于队列尾指针且最后那个月饼花费的总时间比当前的时间更长,那么舍弃这个最后的月饼
				end--;
			yueb[end].t=i;//将当前的花费时间放入队列尾,舍弃原始队列里花费时间比这个长的。
			yueb[end++].wastetime=x;
			while(j



你可能感兴趣的:(单调队列)