poj 4002 Alice's mooncake shop
来源:互联网 发布:win10防火墙设置21端口 编辑:程序博客网 时间:2024/05/16 05:50
题目链接:http://poj.org/problem?id=4002
Alice's mooncake shop
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 525 Accepted: 162
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.
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 ith line( i starts from 1) contains a integer indicating the cost to make a mooncake during the ith hour . The cost is no more than 10000. Jan 1st 2000 0 o'clock belongs to the 1st hour, Jan 1st 2000 1 o'clock belongs to the 2nd hour, …… and so on.
(0<N <= 2500; 0 < M,T <=100000; 0<=S <= 200; R<=10000 ; 0<=H<24)
The input ends with N = 0 and M = 0.
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 ith line( i starts from 1) contains a integer indicating the cost to make a mooncake during the ith hour . The cost is no more than 10000. Jan 1st 2000 0 o'clock belongs to the 1st hour, Jan 1st 2000 1 o'clock belongs to the 2nd hour, …… and so on.
(0<N <= 2500; 0 < M,T <=100000; 0<=S <= 200; R<=10000 ; 0<=H<24)
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 10Jan 1 2000 9 105 220 20 20 10 1087 9 5 100 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.
Maybe you should use 64-bit signed integers. The answer will fit into a 64-bit signed integer.
Source
Fuzhou 2011
[Submit] [Go Back] [Status] [Discuss]
Home Page Go Back To top
可以证明出每个订单都是在一个点,完成的,采用贪心算法,并使用单调队列可解。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<string>#include<bitset>#include<vector>#include<queue>#include<stack>#include<set>#include<map>#include<cstdlib>using namespace std;#define CLR(A) memset(A,0,sizeof(A))struct Node{ int time,num;}cur[2504];struct DEQ{ int pos,v;}que[2504];char month[13][5] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" ,"Dec"};int day[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };inline int find(char *s){for(int i=1;i<=12;i++) if(strcmp(s,month[i])==0) return i;}inline int judge(int x){return x%400==0||x%4==0&&x%100;}inline int solve(int x,int y,int z,int w){bool p;int ret=0;for(int i=2000;i<x;i++){p=judge(i);ret+=365*24;if(p) ret+=24;}p=judge(x);for(int i=1;i<y;i++) ret+=day[p][i]*24;ret+=(z-1)*24+w;return ret;}int main(){ int n,m,t,s; while(~scanf("%d%d",&n,&m)){ if(n==0&&m==0) break; char mon[20]; int x,y,z,w; for(int i=0;i<n;i++){ scanf("%s%d%d%d%d",mon,&z,&x,&w,&cur[i].num); cur[i].time=solve(x,find(mon),z,w); } scanf("%d%d",&t,&s); __int64 ans=0; int head=0,tail=-1,k=0; for(int i=0;i<m;i++){ int x;scanf("%d",&x); while(head<=tail&&que[tail].v+(i-que[tail].pos)*s>=x) tail--; que[++tail].pos=i;que[tail].v=x; while(k<n&&cur[k].time==i){ while(head<=tail&&i-que[head].pos>t) head++; ans+=(que[head].v+(i-que[head].pos)*s)*cur[k++].num; } } cout<<ans<<endl; } return 0;}
0 0
- poj 4002 Alice's mooncake shop
- POJ 4002 Alice's mooncake shop(DP,单调队列)
- hdu1402 Alice's mooncake shop
- HDU4122-Alice's mooncake shop
- HDU 4122 Alice's mooncake shop
- HDOJ 4122 Alice's mooncake shop
- HDU 4122 Alice's mooncake shop
- Hdu 4122 Alice's mooncake shop
- hdu 4122 Alice's mooncake shop题解
- hdu4122 Alice's mooncake shop(单调队列)
- POJ_4002 && HDU_4122 Alice's mooncake shop(RMQ)
- HDU4122 Alice's mooncake shop【单调队列】
- HDU 4122--Alice's mooncake shop(单调队列)
- 单调队列-Hdu-4122-Alice's mooncake shop
- hdu 4122Alice's mooncake shop(单调队列)
- hdu 4122 Alice's mooncake shop(单调队列)
- HDU 4122 Alice's mooncake shop(RMQ:动态最值)
- hdu 4122 Alice's mooncake shop (线段树)
- ubuntu 添加环境变量
- Android—大图or多图加载解决方案(完美解决OOM问题)
- hdu1465不容易系列之一
- java二维数组
- java 图像的直方图均衡化
- poj 4002 Alice's mooncake shop
- c++代码编译
- [POJ 3926][Vjudge 19611] Parade [动态规划+单调队列]
- java面向对象-封装private
- UVA 10815 (暑假-字符串(2) -D - Andy's First Dictionary)
- 导入数据库时出现ORA-01435: 用户不存在
- Ceilometer Distributed Alarm
- 正则表达式
- Codeforces 371C Hamburgers