单调队列,裸的!!坑死了,说好的“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的更多相关文章

  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 --RMQ

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

  6. 【HDOJ】4122 Alice's mooncake shop

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

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

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

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

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

  9. HDU 4122

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

随机推荐

  1. Word Search II 解答

    Question Given a 2D board and a list of words from the dictionary, find all words in the board. Each ...

  2. Safari HTML5 Canvas Guide: Creating Charts and Graphs

    Safari HTML5 Canvas Guide: Creating Charts and Graphs Bar graphs are similar to data plots, but each ...

  3. 一起来学canvas (前言)

    codeyy - 一依丫丫 一起来学canvas (前言)

  4. Unity 两张背景的切换平移

    两张背景图片向左移动,当屏幕看见的时候. 使用的是Unity自带的Sprite,当然也可以使用NGUI Sprite using UnityEngine; using System.Collectio ...

  5. [Java Web]Struts2解决中文乱码问题

    1.设置struts的字符编码,能够在struts.xml中添加下面代码: <constant name="struts.i18n.encoding" value=" ...

  6. php 中利用json_encode和json_decode传递包括特殊字符的数据

    </pre><span style="font-size:24px"></span><pre name="code" ...

  7. 使用lock_sga和pre_page_sga参数保证SGA常驻物理内存 .

    Lock_sga LOCK_SGA locks the entire SGA into physical memory. It is usually advisable to lock the SGA ...

  8. oracle主机修改IP后客户端无法连接

    无论SQLPLUS还是PLSQL Developer连接均报错: ERROR:ORA-12154: TNS: 无法解析指定的连接标识符 解决方法:修改主机IP后,客户端修改tnsnames文件IP:还 ...

  9. U盘变小恢复工具——亲测完美可用

    大白菜U盘,装系统后,U盘损坏,格盘后8G只剩345M,用usbboot恢复到了2G容量.离8G还差很远.用U盘变小恢复工具后,完美恢复到原来大小.在此记录一下,以待下次遇到相似情况使用. 原文地址 ...

  10. 11i - 12 How To Set Email Style Preference For All Users At Once?

    (文档 ID 578574.1) In this Document   Goal   Solution   Workflow Information Center, Diagnostics, & ...