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 ...
随机推荐
- arm linux中添加开机启动
微处理器:S5PV210操作系统:linux3.0.8 前言: 在产品中,基本上都要屏蔽arm开发板中linux系统的对外通信,只应该通过产品的相关APP做相关操作. 因此需要把该APP添 ...
- ##解决 ViewPager 调用 notifyDataSetChanged()无刷新:原理、解决办法##
一.原理 转自:http://www.cnblogs.com/maoyu417/p/3740209.html 转载 http://www.67tgb.com/?p=624 最近项目结束,搞了一次代码分 ...
- MyCat 安装部署,实现数据库分片存储
一.安装MySQL或MariaDB(本文以MariaDB为例) MySQL手动安装方法:点击查看 MariaDB安装: 1.下载MariaDB的repo $ vi /etc/yum.repos.d/M ...
- error LNK2001
error LNK2001: 无法解析的外部符号 "public: virtual void __cdecl Observer::update(float,float,float)" ...
- asp数组的使用
定义简单数组 有两种方法在asp中定义和初始化数组,让我们看看每种的例子: 方法一:MyArray = Array("Jan","Feb","Mar& ...
- 怎样在 Swift 项目中使用 CocoaPods
4个步骤,将 CocoaPods 导入 Swift 1.创建.编辑 Podfile 文件并 pod install 2.使用 File -> New -> File- 创建一个 Heade ...
- 关于 jsp:include 传参的用法
引用模版页面的代码,如下: <jsp:include page="/WEB-INF/template/nav_template.jsp"> <jsp:pa ...
- CSS学习笔记——CSS中定位的浮动float
昨天在解决了盒模型的问题之后又出现了新的知识模糊点:浮动和绝对定位?今天先解决浮动相关的问题,首先列举出想要解决的问题: 1.浮动到底是怎么样的? 2.浮动对元素的影响有什么? 3.浮动主要用来干什么 ...
- Mac下获取AppStore安装包文件路径-取出安装包
问题描述:我们通过AppStore下载软件的时候想要把安装包保存下来,但是AppStore安装好之后会自动删除安装包,而且安装路径也很难找到. 解决方案: 一.打开活动监视器 二.找storedown ...
- UIPickerView(选择控制器) 自学之初体验
UIPickerView 是一个选择器控件, 它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活.UIPickerView 直接继承了 UIView ...