hdu 单调队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4122
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<string>
using namespace std; const int maxn = ; struct Node
{
int id,val;
}; int order[];
long long R[];
int S,T,N,M; struct Myqueue
{
Node Q[maxn];
int head,tail; void init()
{
head = tail = ;
} void push(int id,int val)
{
while(head < tail && Q[tail-].val+S*(id-Q[tail-].id) >= val)
tail--;
Q[tail].val = val;
Q[tail++].id = id;
} void pop(int id)
{
while(head < tail && Q[head].id < id - T) //单调区间的最小值。
head++;
} Node getfront()
{
return Q[head];
}
}solver; map<string,int> mymap; void init()
{
mymap["Jan"] = ; mymap["Feb"] = ; mymap["Mar"] = ;
mymap["Apr"] = ; mymap["May"] = ; mymap["Jun"] = ;
mymap["Jul"] = ; mymap["Aug"] = ; mymap["Sep"] = ;
mymap["Oct"] = ; mymap["Nov"] = ; mymap["Dec"] = ;
} int mou[] = {,,,,,,,,,,,,};
void GetOrder()
{
string s;
int date,year,H; for(int i=; i<=N; i++)
{
cin>>s;
scanf("%d %d %d %I64d",&date,&year,&H,&R[i]);
int mouth = mymap[s];
year -= ;
order[i] = (*+)*(year/);
year = year%;
if(year == )
{
for(int j=; j<mouth; j++)
{
order[i] += mou[j];
if(j == ) order[i] += ;
}
}
else
{
order[i] += + (year-)*;
for(int j=; j<mouth; j++)
order[i] += mou[j];
}
order[i] += date - ;
order[i] = order[i]* + H + ;
}
}
int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
init();
while(cin>>N>>M && N+M)
{
GetOrder(); scanf("%d %d",&T,&S);
solver.init(); int cnt = ;
long long ans = ;
for(int i=; i<=M; i++)
{
int cost;
scanf("%d",&cost); solver.push(i,cost);
solver.pop(i); //先去掉过期的 Node cur = solver.getfront();
while(order[cnt] == i && cnt <= N) //cnt的上限,和while循环,考虑了,为啥不加。
{
ans += (cur.val + (i-cur.id)*S ) * R[cnt]; //乘法溢出问题
cnt ++;
}
}
printf("%I64d\n",ans);
}
}
hdu 单调队列的更多相关文章
- hdu 3401 单调队列优化DP
Trade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 【HDU 3401 Trade】 单调队列优化dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题目大意:现在要你去炒股,给你每天的开盘价值,每股买入价值为ap,卖出价值为bp,每天最多买as ...
- HDU 3401 Trade dp+单调队列优化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...
- 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 3401 Trade(单调队列优化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题意:炒股.第i天买入一股的价钱api,卖出一股的价钱bpi,最多买入asi股,最多卖出bsi股 ...
- HDU 4122 Alice's mooncake shop (单调队列/线段树)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4122 题意:好难读懂,读懂了也好难描述,亲们就自己凑合看看题意把 题解:开始计算每个日期到2000/1/ ...
- Hdu 3410 【单调队列】.cpp
题意: 给出一个数组,问你对于第i个数,从最后一个比它大的数到它之间比它小的数中最大的那个数的下标,以及它右边到第一个比它大的数中比它小的数中最大的那一个数的下标<下标从1开始>. eg: ...
- hdu 4122 Alice's mooncake shop(单调队列)
题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...
- hdu 5945 Fxx and game(单调队列优化DP)
题目链接:hdu 5945 Fxx and game 题意: 让你从x走到1的位置,问你最小的步数,给你两种走的方式,1.如果k整除x,那么你可以从x走一步到k.2.你可以从x走到j,j+t<= ...
随机推荐
- ECMA5.1中关于encodeURI,decodeURI 和encodeComponentURI,decodeComponentURI的区别
The encodeURI and decodeURI functions are intended to work with complete URIs; theyassume that any r ...
- ubuntu下怎么合并windows下分割的zip包
cat ziptest.z* > google_bak.zip 点击打开链接http://blog.51yip.com/linux/988.html
- sae后台管理的js(二)
jsloader cssloader 使用方法<link rel="stylesheet" type="text/css" href="/min ...
- 代码块(block)简介
代码块是对C语言中函数的扩展,由C语言实现,所以在以C为基础的语言内都是有效的,包括Objective_C,C++和Objective-C++,在Xcode的GCG与Clang工具中是有效的,但这不属 ...
- 【原创】Mvc学习笔记(1)
1.新建MVC4项目 在MVC4中有App_Data文件夹,这个文件夹里可以放一些重要的数据,比如说数据库的mdf文件等等,这个文件夹非常安全,因为这个文件夹不允许被别人下载,不允许被浏览器访问. A ...
- 关于OA中权限越级的问题
最近被人问了一个问题, 在OA中我, 经理出差了,下属需要用到 经理的权限,应该怎么处理. 这个问题比较简单,大神,请指点一下. 一开始 ,我就被搞懵了. 我的回答是: 经理出差之前赋给权限就可以了. ...
- html+css篇
一,html语义话标签 http://www.html5jscss.com/html5-semantics-section.html
- OC - 正则表达式 - RegexKitLite
正则表达式使用步骤: 1. 创建正则表达式对象, 设置约束条件; NSString *pattern = @"\\d{1,3}"; NSRegularExpression *reg ...
- OC中格式化输出符号
定义 说明 %@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, ...
- iOS打电话
1,这种方法,拨打完电话回不到原来的应用,会停留在通讯录里,而且是直接拨打,不弹出提示NSMutableString * str=[[NSMutableString alloc] initWithFo ...