Alice's mooncake shop

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2596    Accepted Submission(s): 619

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

 
Source
 

只需要静态查询最小值就可以了。

有一些细节要处理。

 /* ***********************************************
Author :kuangbin
Created Time :2013-11-8 9:59:19
File Name :E:\2013ACM\专题强化训练\区域赛\2011福州\B.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; int getmonth(char s[])
{
if(strcmp(s,"Jan") == ) return ;
if(strcmp(s,"Feb") == ) return ;
if(strcmp(s,"Mar") == ) return ;
if(strcmp(s,"Apr") == ) return ;
if(strcmp(s,"May") == ) return ;
if(strcmp(s,"Jun") == ) return ;
if(strcmp(s,"Jul") == ) return ;
if(strcmp(s,"Aug") == ) return ;
if(strcmp(s,"Sep") == ) return ;
if(strcmp(s,"Oct") == ) return ;
if(strcmp(s,"Nov") == ) return ;
if(strcmp(s,"Dec") == ) return ;
}
int days[] = {,,,,,,,,,,,,};
bool isleap(int y)
{
if(y % == || (y % != && y% == ))return true;
else return false;
}
struct Node
{
char mon[];
int d,y,h;
int R;
int index;
void input()
{
scanf("%s%d%d%d%d",mon,&d,&y,&h,&R);
if(y < )
{
index = -;
return;
}
index = ;
for(int i = ;i < y;i++)
{
if(isleap(i)) index += *;
else index += *;
}
for(int i = ;i < getmonth(mon);i++)
index += days[i]*;
if(isleap(y) && getmonth(mon) > )index += ;
index += (d-)*;
index += h+;
}
}; const int MAXN = ;
long long dp[MAXN][];
long long b[MAXN];
int mm[MAXN];
void initRMQ(int n)
{
mm[] = -;
for(int i = ;i <= n;i++)
{
mm[i] = ((i&(i-)) == )?mm[i-]+:mm[i-];
dp[i][] = b[i];
}
for(int j = ;j <= mm[n];j++)
for(int i = ;i + (<<j) - <= n;i++)
dp[i][j] = min(dp[i][j-],dp[i+(<<(j-))][j-]);
}
long long rmq(int x,int y)
{
int k = mm[y-x+];
return min(dp[x][k],dp[y - (<<k) + ][k]);
} Node node[]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m;
int T,S;
while(scanf("%d%d",&n,&m) == )
{
if(n == && m == )break;
for(int i = ;i < n;i++)
node[i].input();
scanf("%d%d",&T,&S);
for(int i = ;i <= m;i++)
{
scanf("%I64d",&b[i]);
b[i] += (m-i)*S;
}
initRMQ(m);
long long ans = ;
for(int i = ;i < n;i++)
{
if(node[i].index < || node[i].index > m)continue;
long long tmp = rmq(max(,node[i].index - T),node[i].index);
tmp -= (m - node[i].index)*S;
ans += tmp * node[i].R;
}
cout<<ans<<endl;
}
return ;
}

HDU 4122 Alice's mooncake shop (RMQ)的更多相关文章

  1. HDU 4122 Alice's mooncake shop (单调队列/线段树)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4122 题意:好难读懂,读懂了也好难描述,亲们就自己凑合看看题意把 题解:开始计算每个日期到2000/1/ ...

  2. hdu 4122 Alice's mooncake shop(单调队列)

    题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...

  3. HDU 4122 Alice's mooncake shop 单调队列优化dp

    Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  4. HDU 4122 Alice's mooncake shop --RMQ

    题意: 一个月饼店做月饼,总营业时间m小时,只能在整点做月饼,可以做无限个,不过在不同的时间做月饼的话每个月饼的花费是不一样的,假设即为cost[i],再给n个订单,即为在某个时间要多少个月饼,时间从 ...

  5. HDU 4122 Alice's mooncake shop

    单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order. 呢,我就当成严格上升的序列了,于是就各种错.测试 ...

  6. 【HDOJ】4122 Alice's mooncake shop

    RMQ的基础题目,简单题. /* 4122 */ #include <iostream> #include <sstream> #include <string> ...

  7. HDU 3183:A Magic Lamp(RMQ)

    http://acm.hdu.edu.cn/showproblem.php?pid=3183 题意:给出一个数,可以删除掉其中m个字符,要使得最后的数字最小,输出最后的数字(忽略前导零). 思路:设数 ...

  8. HDU 4884 TIANKENG’s rice shop (模拟)

    TIANKENG's rice shop 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/J Description TIANKE ...

  9. HDU 1024 Max Sum Plus Plus (动态规划)

    HDU 1024 Max Sum Plus Plus (动态规划) Description Now I think you have got an AC in Ignatius.L's "M ...

随机推荐

  1. [转]hisi mmz模块驱动讲解

    一.概述 如图所示,在海思平台上将内存分为两个部分:os内存和mmz内存.os内存指:由linux操作系统管理的内存:mmz内存:由mmz驱动模块进行管理供媒体业务单独使用的内存,在驱动加载时可以指定 ...

  2. CSS Pseudo-classes

    先来一条金科玉律: 伪类的效果可以通过添加一个实际的类来达到:伪元素的效果可以通过添加一个实际的元素来达到. 第一部分,Pseudo-classes,伪类 一.链接系 (这个应该是最熟悉的啦.) a: ...

  3. org.hibernate.TransientObjectException异常

    代码如下: /** * 测试4:新增一个秘书角色,并赋给张三该角色 */ @Test public void test4(){ Session session = HibernateUtils.ope ...

  4. Linux sleep命令

    Linux sleep命令可以用来将目前动作延迟一段时间. 使用权限:所有使用者. 语法 sleep [--help] [--version] number[smhd] 参数说明: --help : ...

  5. 洛谷 P4128: bzoj 1815: [SHOI2006]有色图

    题目传送门:洛谷 P4128. 计数好题,原来是 13 年前就出现了经典套路啊.这题在当年应该很难吧. 题意简述: \(n\) 个点的完全图,点没有颜色,边有 \(m\) 种颜色,问本质不同的图的数量 ...

  6. Workflow规则收藏

    豆瓣电影  查看电影评分等详细信息 查看图片EXIF 图铃机器人 快递查询 翻译 手机号码归属地 音乐视频下载 获取附近的免费WIFI

  7. 从requests源码分析中学习python(一)

    v2ex同步更新:https://www.v2ex.com/t/500081 微信公众号:python学习开发 分析源码,看大神的代码是一种学习的好方法,让我从中学到很多以前不知道的知识,这次打算从大 ...

  8. 如何使用windows的计划任务?计划任务?

    我们经常有一些程序想要过了几小时来运行:比如定时关机 或者说希望能够每天的几点执行一个什么程序: 这些所有的操作都需要用到windows的任务计划:或者叫计划任务:反正都一样 下面小编将指导大家创建一 ...

  9. Android 5.0 API

    Android 5.0 (LOLLIPOP) 为用户和应用开发者提供了新功能.本文旨在介绍其中最值得关注的新 API. 如果您有已发布的应用,请务必看一看 Android 5.0 行为变更,了解您的应 ...

  10. VM workstation 与 VM vSphere的区别 [转载]

    在学完vSphere后,想起了VMware Workstation.这两个都是虚拟化的东西,这两者到底有什么本质的不同呢?顺着我的思路我开始将所学过的进行检索期望从中寻到一丝半点的线索.很快大脑中建立 ...