【HDOJ】4122 Alice's mooncake shop
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的更多相关文章
- 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】3660 Alice and Bob's Trip
就是一个基本的dfs.可关键问题是c/c++/g++光输入就超时了.还是写java过的,毕竟时限4s.都放弃希望了,没想到还真过了. import java.lang.*; import java.i ...
- 【HDOJ】3220 Alice’s Cube
状态压缩+逆向BFS.方向数组就是任意相邻的两点(初始化时减1),每个顶点均有4个相邻点.因此,共有16*4/2=32个方向.按序排列即可找到. /* 3220 */ #include <ios ...
- 【HDOJ】4884 TIANKENG's rice shop
简单模拟,注意并不是完全按照FIFO的顺序.比如第i个人的id为k,那么就算第i+1人的id不为k,也会检查他后续的排队人是否有id为k的. #include <cstdio> #incl ...
- HDU 4122 Alice's mooncake shop
单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order. 呢,我就当成严格上升的序列了,于是就各种错.测试 ...
随机推荐
- 安卓项目中使用JSON引发的一个小错误 Multiple dex files define Lorg/apache/commons/collections/Buffer
原因: 这里添加的jar包和android自带的jar产生了冲突
- [Linux] Linux学习笔记(5)-文件与目录管理
1.Linux目录结构为树状结构,最顶层的目录为跟目录"/",其它目录通过挂载可以将它添加到目录树中,通过解除挂载移除它们. 2.绝对路径与相对路径 绝对路径写法:由根目录&quo ...
- VB.Net 字符串加密类
Public Class Cls_JM '使用 'Dim Jm As New Cls_JM(2) 'Dim strTmp As String 'Jm.jiemi(strTmp) 'Jm.Jiami(s ...
- VB6-AppendToLog 通过API写入日志
工作中免不了需要为自己的程序添加日志,我也从网上扒拉了一个老外写的模块,修改修改了下,凑合用吧. Option Explicit '********************************** ...
- Pandas之容易让人混淆的行选择和列选择
在刚学Pandas时,行选择和列选择非常容易混淆,在这里进行一下讨论和归纳 本文的数据来源:https://github.com/fivethirtyeight/data/tree/master/fa ...
- Programming Collective Intelligence
最近正在拜读 O'reilly出版的Programming Collective Intelligence,准备研究研究搜索引擎了,童鞋们,到时候会考虑公布源码哦!
- CodeForces 18C
Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...
- orcale同一条语句运行速度差异问题
在oracle中执行一个查询语句,该语句首次执行时orcale会把其内容存入SGA(系统全局区)中,下次再执行同一条语句的时候就不再去解析该语句,而是直接从SGA区中取出该语句执行,但是前提是SQL没 ...
- Oracle中的USEREVN()
Oracle中的USEREVN() 1.USEREVN() 返回当前用户环境的信息,opt可以是: ENTRYID,SESSIONID,TERMINAL,ISDBA,LABLE,LANGUAGE,CL ...
- Oracle数据库间的数据复制 - SQLPlus中的COPY命令
Copy命令可以实现不同Oracle数据库间的数据的复制,也是可以实现同一数据库的数据复制,其性能表现和导入/导出相同. 根据9i文档,说Copy命令未来会不支持,但实际上Oracle 11g仍然支持 ...