【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. 呢,我就当成严格上升的序列了,于是就各种错.测试 ...
随机推荐
- javascript 代码优化工具 UglifyJS
安装: 1. 安装 node.js 环境 (这个不用我教了吧,网上教程一大堆哦.) 2. 进入 https://github.com/mishoo/UglifyJS 右上角 “Download” Z ...
- c#winform,制作可编辑html编辑器
大神勿喷,新手记笔记 材料 网上下载kindeditor,动手在写个htmldome,图中的e.html.然后全部扔到了bin/debug下面,(x86是要扔到bin/x86/debug) 中间bod ...
- js控制进度条到达100%跳转界面一
进度条一般在手机上用到的比较广泛,刚好最近的项目也是一直在做手机站,这个特效是手机端的一个界面,现在我把改成pc端了,进度条的快慢速度和样式可自行调节,改动也是很方便的,不多说,看代码: <st ...
- Java 多线程 锁 存款 取款
http://jameswxx.iteye.com/blog/806968 最近想将java基础的一些东西都整理整理,写下来,这是对知识的总结,也是一种乐趣.已经拟好了提纲,大概分为这几个主题: ja ...
- 好用的ssh工具oh-my-zsh / iterm2
The manual way 1. Clone the repository: git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh- ...
- cc2640-各DEMO板性能分析
一.测试方法: 将4种模块同时上电,测量每个模块达到的最远距离.以稳定能建立通讯为连接上依据.4种板子分析为 1号阿莫DEMO板,2号咱们自己DEMO板,3号嘉源电子DEMO,4号陆程电子DEMO 全 ...
- mac 下 sphinx + mysql + php 实现全文搜索(xampp)(3)sphinx 的配置项解析
source:数据的来源,数据是从什么地方来的. index:索引,当有数据源之后,从数据源处构建索引.索引实际上就是相当于一个字典检索.有了整本字典内容以后,才会有字典检索. searchd:提供搜 ...
- Java 多线程 简单实例 (消费者与生成者)的关系
PS::线程这套东西在PHP里完全是不存在的概念,有待进一步的学习: PS::这个实例是根据书本上的知识进行扩展的,理解程度50%左右吧! 1.定义生产消费环境 package second; pub ...
- PHP - PDO 之 mysql 事务功能
<?php /* pdo 学习 */ $dsn = 'mysql:host=localhost;dbname=cswl';//构建连接dsn $db = new pdo($dsn,'root', ...
- (转载)Cocos2dx-OpenGL ES2.0教程:初识MVP(3)
在上一篇文章中,我在介绍vertex shader的时候挖了一个坑:CC_MVPMatrix.它其实是一个uniform,每一个cocos2d-x预定义的shader都包含有这个uniform, 但是 ...