题目链接:

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

题目意思:

一家月饼店,有n个订单,从2001年1月1日0时开始24小时营业开m个小时,且每个时间点做一个月斌的花费不一样,每个订单由时间(年月日时)定月饼数量组成。店主在每个整时点都可以做月饼,并且做月饼的时间可以忽略。每个月饼有保质期t,保存每个月饼每小时需花费s。求完成所有订单,最少的花费。

解题思路:

1、先算出每个订单的小时点。

2、对每个订单时间点i,很显然花费min(cost[j]+(i-j)*s)(i-j<=t)最划算。cost[j]+(i-j)*s=cost[j]-j*s+i*s,所以对于每个i,求出前面的满足j>=i-t,的cost[j]-j*s的最小值即可,很显然用单调队列可以维护。

代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; //0表示平年,1表示闰年
int days[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};
int dd[2]={365,366}; //每年的天数
map<string,int>myp;
string mon;
#define Maxn 2700
#define Maxm 110000
ll pp[Maxn],hh[Maxn];//订单的月饼数量和时间点
ll q[Maxm],cost[Maxm];//花费
ll Mi[Maxm];//Mi[i]表示时间点i时的最小花费单价
ll n,m; bool isleap(int y) //是否为闰年
{
if((y%4==0&&y%100)||(y%400==0))
return true;
return false;
} ll Cal(int y,int m,int d,int h) //计算距离2000年1月1日0时的小时数,从开始标记
{
ll res=0;
for(int i=2000;i<y;i++) //计算前面的年份
res+=dd[isleap(i)]*24;
int is=isleap(y);
for(int i=1;i<m;i++) //计算当前年的前面月的天数
res+=days[is][i]*24;
res+=(d-1)*24;//当月的小时数
res+=(h+1); //从1小时开始记
return res; } int main()
{
myp["Jan"]=1,myp["Feb"]=2,myp["Mar"]=3,myp["Apr"]=4;
myp["May"]=5,myp["Jun"]=6,myp["Jul"]=7,myp["Aug"]=8;
myp["Sep"]=9,myp["Oct"]=10,myp["Nov"]=11,myp["Dec"]=12;
int mon,day,yea,hour; while(scanf("%I64d%I64d",&n,&m)&&n+m)
{
for(int i=1;i<=n;i++)
{
string a;
cin>>a>>day>>yea>>hour>>pp[i];
hh[i]=Cal(yea,myp[a],day,hour);
}
ll t,s; scanf("%I64d%I64d",&t,&s);
for(int i=1;i<=m;i++)
{
scanf("%I64d",&cost[i]);
cost[i]-=i*s; //需要维护的值
} int head=1,tail=0; //从1开始标号 // printf("%I64d\n",m);
for(int i=1;i<=m+1;i++)
{
while(head<=tail&&cost[q[tail]]>=cost[i])
tail--;
q[++tail]=i;
while(head<=tail&&q[head]+t<i)
head++;
Mi[i]=cost[q[head]]+i*s;
}
//printf(":%I64d\n",Mi[10]);
ll ans=0;
for(int i=1;i<=n;i++)
ans+=Mi[hh[i]]*pp[i];
printf("%I64d\n",ans);
//printf("%I64d\n",Mi[hh[i]]*pp[i]); }
return 0;
}

单调队列-Hdu-4122-Alice's mooncake shop的更多相关文章

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

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

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

  3. HDU 4122 Alice's mooncake shop (RMQ)

    Alice's mooncake shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

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

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

  5. HDU 4122 Alice's mooncake shop

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

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

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

  7. 【HDOJ】4122 Alice's mooncake shop

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

  8. Alice's mooncake shop HDU - 4122 单调队列

    题意: 有n个订单和可以在m小时内制作月饼,制作月饼不考虑时间(即,你可以在一个时刻在所有需要的月饼都做完) 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接下来一 ...

  9. hdu 4122 Alice&#39;s mooncake shop (线段树)

    题目大意: 一个月饼店每一个小时做出月饼的花费不一样. 储存起来要钱.最多存多久.问你把全部订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ...

  10. HDU 4122

    Alice's mooncake shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. 高性能MySql进化论【转】

    高性能MySql进化论(十二):Mysql中分区表的使用总结 http://binary.duapp.com/category/sql 当数据量非常大时(表的容量到达GB或者是TB),如果仍然采用索引 ...

  2. [IOI1999]花店橱窗布置(DP路径记录)

    题目:[IOI1999]花店橱窗布置 问题编号:496 题目描述 某花店现有F束花,每一束花的品种都不一样,同时至少有同样数量的花瓶,被按顺序摆成一行,花瓶的位置是固定的,从左到右按1到V顺序编号,V ...

  3. asp net 编程问题 实现下一篇 和上一篇效果

    首先是access数据库,有一个名为news的表,里面有三个字段,分别为id,classid 和name 其中id为主键,classid可以重复 现在有以下数据: id classid name 1 ...

  4. 犯罪团伙 codevs 3554

    这是一道经典的水题,提供两种方法:①深搜  ②并查集 NO.1 深度优先搜索: #include<iostream>#include<cstdio>#include<al ...

  5. [翻译] C++ STL容器参考手册 (总册)

    1. 写在最前面 这将是博主的第一篇技术博客,思考再三决定从翻译开始.这将是一个系列的博客,由不同的章节组成,章节之间由超链接联系,开发过程将使用增量式开发,每次完成一个章节.本篇是本系列的总册,提供 ...

  6. 连接SQLite 创建ADO.net实体类

    0.开发环境 win10,vs2013-x64 1.安装: sqlite-netFx451-setup-bundle-x86-2013-1.0.102.0.exe 注意事项:选在VisualStudi ...

  7. shell中的type命令

    type [-aftpP] name [name,...] -a 打印name的所有可能情况,比如type -a ls,会打印ls is aliased to 'ls --color=auto'和ls ...

  8. Mysql学习(慕课学习笔记4)创建数据表、查看数据表、插入记录

    创建数据表 Create table [if not exists] table_name(column_name data_type,…….) UNSIGNED 无符号SIGNED 有符号 查看创建 ...

  9. js迭代器模式

    在迭代器模式中,通常有一个包含某种数据的集合的对象.该数据可能储存在一个复杂数据结构内部,而要提供一种简单 的方法能够访问数据结构中的每个元素. 实现如下: //迭代器模式 var agg = (fu ...

  10. Oracle11g R2学习系列 之九 PL/SQL语言

    这是个重头戏,如果精通了PL/SQL,毫不夸张的说明精通了Oracle了.PL/SQL由以下三个部分组成(Definition,Manipulation,Control): DDL:数据定义语言,Cr ...