HDU 4122 Alice's mooncake shop (单调队列/线段树)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4122
题意:好难读懂,读懂了也好难描述,亲们就自己凑合看看题意把
题解:开始计算每个日期到2000/1/1日0点有多少个小时,然后求出每个小时的时候每个的最小单价(包括成本+储存费用)
使用单调队列,维护队列,使之到i 生产的最优
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; #define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sd1(a) scanf("%lf",&a)
#define sd2(a,b) scanf("%lf%lf",&a,&b)
#define ss1(s) scanf("%s",s)
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d %d\n",a,b)
#define mset(a,b) memset(a,b,sizeof(a))
#define forb(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i<=b;i++) typedef __int64 LL;
const int N=110001;
const int M=1000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-7; LL n,m,s,t;
char ss[100];
int mm[13],yy[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
map<string,int> mp;
struct node
{
int t,num;
}q[3333*4],order[3333]; bool isrun(int y)
{
if(y%400==0||(y%4==0&&y%100!=0))
return true;
return false;
} int run(int y1,int y2)
{
int num=0;
for(int i=y1;i<y2;i++)
if(i%400==0||(i%4==0&&i%100!=0))
num++;
return num;
} int main()
{
mm[0]=0;
for(int i=1;i<=12;i++)
mm[i]=mm[i-1]+yy[i];
mp["Jan"]=1;
mp["Feb"]=2;
mp["Mar"]=3;
mp["Apr"]=4;
mp["May"]=5;
mp["Jun"]=6;
mp["Jul"]=7;
mp["Aug"]=8;
mp["Sep"]=9;
mp["Oct"]=10;
mp["Nov"]=11;
mp["Dec"]=12; while(scanf("%I64d%I64d",&n,&m)&&(n+m))
{
for(int i=0;i<n;i++)
{
string ss;
int ri,nian,shi,ge;
cin>>ss;
scanf("%d%d%d%d",&ri,&nian,&shi,&order[i].num);
int yue=mp[ss];
int sum=(nian-2000)*365+run(2000,nian);
sum+=mm[yue-1]+ri-1;
if(yue>2&&isrun(nian)) sum++;
order[i].t=sum*24+shi;
}
int top=0,tail=0,p=0,t,s;
LL sum=0;
scanf("%d%d",&t,&s);
for(int i=0;i<m;++i)
{
int a;
scanf("%d",&a);
while(top<tail && q[tail-1].num+(i-q[tail-1].t)*s>=a)--tail;
q[tail].num=a,q[tail++].t=i;
while(p<n && i == order[p].t)
{
while(q[top].t+t<i)++top;
sum+=(q[top].num+(i-q[top].t)*s)*order[p++].num;
}
}
printf("%I64d\n",sum);
}
return 0;
}
/*
1 10
Jan 1 2000 9 10
5 2
20
20
20
10
10
8
7
9
5
10
0 0
*/
HDU 4122 Alice's mooncake shop (单调队列/线段树)的更多相关文章
- hdu 4122 Alice's mooncake shop(单调队列)
题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...
- 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 ...
- 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 ...
- HDU 4122 Alice's mooncake shop
单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order. 呢,我就当成严格上升的序列了,于是就各种错.测试 ...
- HDU 4122 Alice's mooncake shop --RMQ
题意: 一个月饼店做月饼,总营业时间m小时,只能在整点做月饼,可以做无限个,不过在不同的时间做月饼的话每个月饼的花费是不一样的,假设即为cost[i],再给n个订单,即为在某个时间要多少个月饼,时间从 ...
- poj3162 树形dp|树的直径 + 双单调队列|线段树,好题啊
题解链接:https://blog.csdn.net/shiqi_614/article/details/8105149 用树形dp是超时的,, /* 先求出每个点可以跑的最长距离dp[i][0|1] ...
- [洛谷P1886]滑动窗口 (单调队列)(线段树)
---恢复内容开始--- 这是很好的一道题 题目描述: 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口. 现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的 ...
- newcoder H肥猪(单调队列 / 线段树)题解
题意: 小B来到了一个异世界,成为了肥猪之王. 在这个异世界,共有n种肥猪,编号分别为1,...,n. 小B希望集齐这n种肥猪. 召集肥猪有两种方式: 1. 花费a[i]的金币召唤一只编号为i的肥猪. ...
- POJ 2823 Sliding Window(单调队列 || 线段树)题解
题意:求每个长度为k的数组的最大值和最小值 思路: 1.用线段树创建维护最大值和最小值,遍历询问,简单复习了一下...有点手生 2.单调队列: 可以看一下详解 单调队列顾名思义就是一个单调递增或者递减 ...
随机推荐
- [Angular 2] Using events and refs
This lesson shows you how set listen for click events using the (click) syntax. It also covers getti ...
- [转载]aptitude与apt-get的区别和联系
转自 http://www.cnblogs.com/yuxc/archive/2012/08/02/2620003.html 命令 下面将要介绍的所有命令都需要sudo!使用时请将“packagena ...
- F# 越用越喜欢
F# 越用越喜欢 最近由于需要,把遗忘了几年的F#又捡了起来.说捡了起来,倒不如说是从头学习,原来学的早已经忘了!所谓学过,只不过看过一本<F# 语言程序设计> (郑宇军 凌海风 编著 - ...
- keydown和keypress
常见的键盘事件是keyup和keydown.淡蓝就经常用 document.onkeyup = function (e) { if ((e.keyCode || e.which) === 13) // ...
- Opencv 函数
1.cvLoadImage:将图像文件加载至内存: 2.cvNamedWindow:在屏幕上创建一个窗口: 3.cvShowImage:在一个已创建好的窗口中显示图像: 4.cvWaitKey:使程序 ...
- [Leetcode] implement strStr() (C++)
Github leetcode 我的解题仓库 https://github.com/interviewcoder/leetcode 题目: Implement strStr(). Returns ...
- 无法捕获的异常:MissingMethodException
今天一个同事发布站点,一直出现一些稀奇古怪的问题,各种各样的异常都有,根据这些异常去排查代码,都完全正常,很让人郁闷,因为代码里可能出异常的地方都记录了程序日志,所以他一直没去排查系统里的“应用程序日 ...
- No-args constructor for class does not exist. Register an InstanceCreator with G
有时候我们在使用Googel官方的json解析包时,如果自己的实体类中出现代参的构造函数.在1.4的jar中,如果类造型中有参数,就会调用不了无参构造器,(如:HashMap的构造器就会有参数) 参考 ...
- 一个支持实时预览的在线 Markdown 编辑器 - Markdoc
最近组内需要为一些项目和系统写文档,发表在公司内的文档平台上,这个平台并不支持markdown,所以打算做一个在线markdown编辑器,支持实时预览,并且可以很容易的迁移发表到公司文档平台上,所以就 ...
- 模拟Sping MVC
在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...