HDU 4122 Alice's mooncake shop
单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order. 呢,我就当成严格上升的序列了,于是就各种错。测试数据是有重复元素的!!!
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<sstream>
#include<vector>
#include<string>
#include<cstdio>
#include<bitset>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define MP make_pair
#define eps 1e-10
using namespace std; const int N = 3333;
const int M = 111111; int order[N], tim[N], pay[M];
char month[15][5] = {"zero", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int hav[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char mo[5];
int p[M];
int n, m, t, s, y, h, r, d;
map<string, int> mp; void pre()
{
int i;
mp.clear();
for(i = 1; i <= 12; i ++)
{
mp[month[i]] = i;
}
} int get_tm(int m, int d, int y, int h)
{
int ret = 0, i;
for(i = 0; i < y; i ++)
{
if(i % 4 == 0) ret += 366 * 24;
else ret += 365 * 24;
}
for(i = 1; i < m; i ++)
{
ret += hav[i] * 24;
if(i == 2 && y % 4 == 0) ret += 24;
}
ret += (d - 1) * 24 + h;
return ret;
} void input()
{
int i, j;
for(i = 0; i < n; i ++)
{
scanf("%s%d%d%d%d", mo, &d, &y, &h, &r);
order[i] = r;
tim[i] = get_tm(mp[mo], d, y - 2000, h);
}
scanf("%d%d", &t, &s);
for(i = 0; i < m; i ++)
{
scanf("%d", &pay[i]);
}
} void slove()
{
int l = 0, r = 0, i = 0, j = 0;
LL ans = 0;
p[r ++] = 0;
while(i < m)
{ while(pay[i] <= pay[p[r - 1]] + (i - p[r - 1]) * s && r > l) r --;
p[r ++] = i;
while(i - p[l] > t) l ++;
while(j < n && i == tim[j])ans += (pay[p[l]] + (i - p[l]) * (LL)s) * (LL)order[j], j ++;
i ++;
}
printf("%I64d\n", ans);
} int main()
{
//freopen("input.txt", "r", stdin);
pre();
while(scanf("%d%d", &n, &m), n + m)
{
input();
slove();
}
return 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 (单调队列/线段树)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4122 题意:好难读懂,读懂了也好难描述,亲们就自己凑合看看题意把 题解:开始计算每个日期到2000/1/ ...
- HDU 4122 Alice's mooncake shop --RMQ
题意: 一个月饼店做月饼,总营业时间m小时,只能在整点做月饼,可以做无限个,不过在不同的时间做月饼的话每个月饼的花费是不一样的,假设即为cost[i],再给n个订单,即为在某个时间要多少个月饼,时间从 ...
- 【HDOJ】4122 Alice's mooncake shop
RMQ的基础题目,简单题. /* 4122 */ #include <iostream> #include <sstream> #include <string> ...
- hdu 4122 Alice's mooncake shop (线段树)
题目大意: 一个月饼店每一个小时做出月饼的花费不一样. 储存起来要钱.最多存多久.问你把全部订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ...
- Alice's mooncake shop HDU - 4122 单调队列
题意: 有n个订单和可以在m小时内制作月饼,制作月饼不考虑时间(即,你可以在一个时刻在所有需要的月饼都做完) 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接下来一 ...
- HDU 4122
Alice's mooncake shop Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- plsql在64位机器下读取tnsname.ora 及oracle_home异常的解决办法
问题是: 我在自己电脑(win7 64bit)上安装了oracle的64位数据库 通过sqlplus能正常连接 主要是安装pl/sql时 我是这样安装的1.在网上下载了个instantcli ...
- Android性能优化典范【转】
2015年伊始,Google发布了关于Android性能优化典范的专题,一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍了Android系统中有关 ...
- ZOJ3578(Matrix)
Matrix Time Limit: 10 Seconds Memory Limit: 131072 KB A N*M coordinate plane ((0, 0)~(n, m)). I ...
- 把Storyboard减轻的方法
把Storyboard减轻的方法 by 伍雪颖 UIViewController *secondStoryboard = [[UIStoryboard storyboardWithName:@&quo ...
- Unity uGUI 登录及注册功能
上次我们已经完成了登录界面的模拟功能,今天咱们把上次没做完的继续完善下!那么废话少说直接开始吧! PS:本次完善的功能有: 1,增加对数据库的操作. 2,使用了MD5Key值加密 3,完善登录和组测功 ...
- 本地无sqlserver服务下操作数据库 之GSQL
作为程序员无论是我们写的各种MIS系统还是游戏都离不开数据的存取操作,正如我们前几天在VS下做的一MIS系统,现在纠结. 如果是C/S或B/S模型就好了,可是需求不是,没办法,顾客是上帝...他们的需 ...
- DataSet转Json 方法
防止忘记,留着备用 /// <summary> /// DATASET转JSON /// </summary> /// <param name="ds" ...
- 16进制字符串转换为byte数组
/// <summary> /// 16进制字符转换为byte数组 /// </summary> /// <param name="hexString" ...
- node学习 process笔记
如果你是node大神好了可以关闭此页面了因为接下来游览会白白浪费你许多时间,最近一直学习node.js今晚看到 alsotang 在 github上的node教程 https://github.com ...
- css基础之 联网使用bootstrap
在<head></head>中添加 <meta charset="utf-8"> <meta http-equiv="X-UA- ...