BZOJ 1113: [Poi2008]海报PLA
1113: [Poi2008]海报PLA
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 1025 Solved: 679
[Submit][Status][Discuss]
Description
N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们.
Input
第一行给出数字N,代表有N个矩形.N在[1,250000] 下面N行,每行给出矩形的长与宽.其值在[1,1000000000]2 1/2 Postering
Output
最少数量的海报数.
Sample Input
1 2
1 3
2 2
2 5
1 4

Sample Output

HINT
Source
分析
单调栈
代码
/*<--- Opinion --->*/ #define HEADER
#define MYMATH
// #define FILEIO
// #define FSTREAM
// #define FREOPEN
#define FASTREAD
#define SHORTNAME ///// HEADER FILE ///// #ifdef HEADER #include <cmath>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> #include <sstream>
#include <fstream>
#include <iostream> #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <functional> #endif ///// SHORTNAME ///// #ifdef SHORTNAME #define LL long long
#define ll long long
#define re register
#define un unsigned
#define rb re bool
#define ri re int
#define ui un int
#define rl re LL
#define ul un LL #define rep (x, y) for (ri i = x; i <= y; ++i)
#define repi(x, y) for (ri i = x; i <= y; ++i)
#define repj(x, y) for (ri j = x; j <= y; ++j)
#define repk(x, y) for (ri k = x; k <= y; ++k) #define upto(x) for (ri i = 1; i <= x; ++i)
#define dnto(x) for (ri i = x; i >= 1; --i) #define up(x) for (ri i = 1; i <= x; ++i)
#define dn(x) for (ri i = x; i >= 1; --i) #define put(x) printf("%lld ", (LL)x)
#define putln(x) printf("%lld\n", (LL)x) #endif ///// FASTREAD ///// #ifdef FASTREAD const int FR_lim = ; char *FR_c; inline void fsetup(FILE *FR_file)
{
FR_c = new char[FR_lim];
fread(FR_c, , FR_lim, FR_file);
} template <class T>
inline void fread(T &FR_num)
{
FR_num = ; rb FR_neg = ; while (*FR_c < '')
if (*FR_c++ == '-')
FR_neg ^= true; while (*FR_c >= '')
FR_num = FR_num* + *FR_c++ - ''; if(FR_neg)FR_num = -FR_num;
} #endif ///// FILE I/O ///// #ifdef FILEIO FILE *FIN = fopen("input.txt", "r");
FILE *FOUT = fopen("output.txt", "w"); #ifndef FSTREAM #define fin FIN
#define fout FOUT #endif #endif ///// FSTREAM ///// #ifdef FSTREAM std::ifstream fin("input.txt");
std::ofstream fout("output.txt"); #endif ///// MYMATH ///// #ifdef MYMATH #define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b) #define Min(a, b) a = min(a, b)
#define Max(a, b) a = max(a, b) #define abs(x) (x < 0 ? -x : x) #define sqr(x) ((x)*(x)) #endif ///// _MAIN_ ///// void _main_(void); signed main(void)
{ #ifdef FREOPEN
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif _main_(); #ifdef FILEIO
fclose(FIN);
fclose(FOUT);
#endif #ifdef FREOPEN
fclose(stdin);
fclose(stdout);
#endif #ifdef FSTREAM
fin.close();
fout.close();
#endif return ;
} /*<--- Main --->*/ #define N 250005 int n;
int ans;
int h[N];
int stk[N];
int tot = ; void _main_(void)
{
fsetup(stdin); fread(n); ri x; up(n)
{
fread(x); fread(x);
while (tot && stk[tot] > x)--tot;
if (tot && stk[tot] == x)++ans;
stk[++tot] = x;
} putln(n - ans);
}
BZOJ_1113.cpp
好像那天特别高兴的样子,不知不觉就敲了个不明所以的模板, 补一份正常的代码。
#include <bits/stdc++.h>
signed main(void) {
int n, tot = ;
scanf("%d", &n);
std::stack<int> stk;
for (int i = ; i <= n; ++i) {
int h; scanf("%*d%d", &h);
while (!stk.empty() && h < stk.top())
stk.pop();
if (!stk.empty() && h == stk.top())
++tot;
stk.push(h);
}
printf("%d\n", n - tot);
}
BZOJ_1113.cpp
@Author: YouSiki
BZOJ 1113: [Poi2008]海报PLA的更多相关文章
- bzoj 1113 [Poi2008]海报PLA 单调栈
[Poi2008]海报PLA Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1304 Solved: 896[Submit][Status][Dis ...
- 1113: [Poi2008]海报PLA
1113: [Poi2008]海报PLA Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 765 Solved: 466[Submit][Status ...
- BZOJ——T 1113: [Poi2008]海报PLA
http://www.lydsy.com/JudgeOnline/problem.php?id=1113 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: ...
- BZOJ1113 Poi2008 海报PLA【单调栈】【水】
BZOJ1113 Poi2008 海报PLA Description N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们. Input 第一行给出数字N,代表有N个矩形.N在[1,250 ...
- bzoj1113: [Poi2008]海报PLA
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- BZOJ1113 [Poi2008]海报PLA 【分治 + 线段树】
题目链接 BZOJ1113 题解 显然只与高有关,每次选择所有海报中最低的覆盖所有海报,然后分治两边 每个位置会被调用一次,复杂度\(O(nlogn)\) \(upd:\)智障了,,是一道\(O(n) ...
- [POI2008]海报PLA
Description N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们. Input 第一行给出数字N,代表有N个矩形.N在[1,250000] 下面N行,每行给出矩形的长与宽.其值 ...
- BZOJ1113 海报PLA
好像是很古老的题?现在BZOJ上找不到该题,所以没有提交. 1113: [Poi2008]海报PLA Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 8 ...
- 【BZOJ-1113】海报PLA 单调栈
1113: [Poi2008]海报PLA Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 896 Solved: 573[Submit][Status ...
随机推荐
- http协议(四)http状态码
一:http状态码 表示客户端http请求的返回结果.标记服务器端的处理是否正常.通知出现的错误等工作 状态码的类别如下: http状态码种类繁多,大概有60多种,实际上经常使用的只有14种,下面为一 ...
- 1D1D动态规划优化初步
再学习一下动态规划的基本优化方法- 首先这篇文章应该大家都看过吧-没看过的自行百度 关于实现的思路文章里都给好了-这篇就主要给一点题目啥的 (P.S. 电脑重装了,如果博客发出来有一些奇怪的问题不要在 ...
- 产品经理技能之BRD的笔记之菜鸟入门
链接:http://www.woshipm.com/pmd/178527.html?utm_source=tuicool 要学习MRD.PRD,先从BRD开始,才能做到知其然知其所以然. BRD是什么 ...
- Dell 服务器做Raid
Dell 服务器做Raid DELL R720 服务器 RAID阵列卡配置介绍 (H310) 关于 RAID 5 与热备份(Hot Spare) 在不同RAID组间使用热备盘——Global Hot ...
- 利用windbg查找dictionary导致IIS占CPU100%案例分析(一)
一.背景 先说下windbg使用场景.各位coder在工作中或多或少都会遇到下面四种情况 1.本地代码好好的,放服务器上运行一段时间后,IIS服务突然占用 w3wp.exe CPU突然100% ,不得 ...
- 【转】加快网站访问速度——Yslow极限优化
Yslow是一套雅虎的网页评分系统,详细的列出了各项影响网页载入速度的参数,这里不做多说. 我之前就一直参考Yslow做博客优化,经过长时间的学习也算是有所收获,小博的YslowV2分数达到了94分( ...
- 领导让我重新做一个微信H5页面!
leader:我们需要做一个微信H5页面,效果如图,功能如描述,时间越快越好. 需求是不是很简单呢?2015-11-24 12:44:00文末有最新更新 背景描述 前几天微信转发相关项目开发后,这是第 ...
- 从Nodejs脚本到vue首页看开源始末的DemoHouse
最近上Github看见了大漠的DemoHouse项目,看到Issues说准备做一个首页,于是我的第一想法就是做一个md列表页面,md文件可以很容易的生成一个html文件.刚刚做好脚本文件,可以生成li ...
- 项目分布式部署那些事(1):ONS消息队列、基于Redis的Session共享,开源共享
因业务发展需要现在的系统不足以支撑现在的用户量,于是我们在一周之前着手项目的性能优化与分布式部署的相关动作. 概况 现在的系统是基于RabbitHub(一套开源的开发时框架)和Rabbit.WeiXi ...
- 自定义getElementByClass
DOM已经实现了getElementByClass,这个功能内部是怎么实现的呢 js代码及如何使用: function getElementByClass(className,parentNode){ ...