RMQ的基础题目,简单题。

 /* 4122 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxm = 1e5+;
const int maxn = ;
int T[maxn], N[maxn];
int cost[maxm], val[maxm];
int dp[maxm][];
int days[] = {
, , , , , ,
, , , , ,
};
int days_[] = {
, , , , , ,
, , , , ,
};
char month[][] = {
"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"
};
char s[];
int yy, mm, dd, hh;
int n, m; int getMon(char *s) {
rep(i, , )
if (strcmp(month[i], s) == )
return i; return -;
} bool isLeapYear(int y) {
return y%== || (y%!= && y%==);
} int getTime() {
mm = getMon(s);
int ret = ; rep(i, , yy) {
if (isLeapYear(i))
ret += ;
else
ret += ;
}
if (isLeapYear(yy)) {
rep(i, , mm)
ret += days_[i];
} else {
rep(i, , mm)
ret += days[i];
}
ret += dd-;
ret *= ;
ret += hh + ; return ret;
} void init_RMQ() {
int i, j; for (i=; i<m; ++i)
dp[i][] = i; for (j=; (<<j)<=m; ++j) {
for (i=; i+(<<j)-<m; ++i) {
if (val[dp[i][j-]] < val[dp[i+(<<(j-))][j-]])
dp[i][j] = dp[i][j-];
else
dp[i][j] = dp[i+(<<(j-))][j-];
}
}
} int RMQ(int l, int r) {
if (l < )
l = ; int k = ; while (<<(k+) <= r-l+)
++k; if (val[dp[l][k]] < val[dp[r-(<<k)+][k]])
return dp[l][k];
else
return dp[r-(<<k)+][k];
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int st, cst;
int idx, tmp;
__int64 ans; while (scanf("%d%d", &n, &m)!=EOF && (n||m)) {
rep(i, , n) {
scanf("%s%d%d%d%d", s, &dd, &yy, &hh, &N[i]);
T[i] = getTime();
}
scanf("%d%d", &st, &cst);
rep(i, , m) {
scanf("%d", &cost[i]);
val[i] = cost[i] + cst * (m - i);
} ans = ;
init_RMQ();
rep(i, , n) {
idx = RMQ(T[i]-st, T[i]-);
tmp = cost[idx] + (T[i]--idx) * cst;
ans += 1LL * tmp * N[i];
} printf("%I64d\n", ans);
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】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】3660 Alice and Bob's Trip

    就是一个基本的dfs.可关键问题是c/c++/g++光输入就超时了.还是写java过的,毕竟时限4s.都放弃希望了,没想到还真过了. import java.lang.*; import java.i ...

  7. 【HDOJ】3220 Alice’s Cube

    状态压缩+逆向BFS.方向数组就是任意相邻的两点(初始化时减1),每个顶点均有4个相邻点.因此,共有16*4/2=32个方向.按序排列即可找到. /* 3220 */ #include <ios ...

  8. 【HDOJ】4884 TIANKENG's rice shop

    简单模拟,注意并不是完全按照FIFO的顺序.比如第i个人的id为k,那么就算第i+1人的id不为k,也会检查他后续的排队人是否有id为k的. #include <cstdio> #incl ...

  9. HDU 4122 Alice's mooncake shop

    单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order. 呢,我就当成严格上升的序列了,于是就各种错.测试 ...

随机推荐

  1. jquery.ajax中的ifModified参数的误解

    原来以为ifModified是为了在AJAX请求是发送 If-Modified-Since头,让服务端返回304. 测试代码如下: $(function () { test(); window.set ...

  2. css圆角 四边投影

    -moz-border-radius: 30px;-webkit-border-radius: 30px; border-radius:30px; -webkit-box-shadow:0 0 10p ...

  3. mouseenter 事件,固定右侧客服特效

    不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. 当鼠标指针离开元素时,会发生 mouseleave 事件 ...

  4. asp.net runat="server" && hiddenfield

    runat="server", c#可以直接获得client控件,并且赋值 hiddenfield 可以作为传值,或者界面存值,后台每次读取,并且再赋值到前台,这样前台就可以把上一 ...

  5. Opencv Mat的操作

    cout << mat 有错误的原因 You are using OpenCV built with VS10. The ostream operator << in the ...

  6. SQL Server是如何让定时作业

    如果在SQL Server 里需要定时或者每隔一段时间执行某个存储过程或3200字符以内的SQL语句时,可以用管理->SQL Server代理->作业来实现. 1.管理->SQL S ...

  7. 计算器(delphi)

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  8. Linux 配置Samba

    配置Samba 如果没有普通用户,添加用户,指令: useradd -m aaa passwd bbb 添加Samba用户指令: smbpasswd -a aaa passwdword: …… 修改配 ...

  9. .net google calendar

    https://developers.google.com/gdata/client-cs http://www.codeproject.com/Articles/64474/How-to-Read- ...

  10. 隐藏和显示效果js动画

    <div id='ctt' style='margin-left: 50px; color: white'>             <input type="button ...