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 ...
随机推荐
- STL标准库面试常考知识点
C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构操作.vecto ...
- Win10添加简体中文美式键盘的方法
在Win10中很多朋友发现没有简体中文(美式键盘)的选项,而如果使用“英语-美式键盘”作为默认输入法,有ModernApp的界面会变成英文,这十分不方便,那么有没有方可以在Win10中添加一个 简体中 ...
- .net AES加密解密
using System; using System.Collections.Generic; using System.Text; using System.Secur ...
- Linux shell特性
一:别名 .alias 查看本用户下的alias配置 --自定义别名:alias 别名='shell命令' (注意是单引号) --cat $HOME/.bashrc 在这个用户下配置着alias名的配 ...
- UDP的坏处
众所周知,UDP是一个面向无连接的协议.通信时不可靠的.这就会出现一些问题 (1)数据报丢失 因为是无连接,的所以可以用recvfrom和sendto来接收和发送消息,如果socket是阻塞的,那么当 ...
- java 客户端链接不上redis解决方案
原文地址:http://blog.csdn.net/yingxiake/article/details/51472810 出现问题描述: 1.Could not get a resource from ...
- 详解c++指针的指针和指针的引用
展示一下使用指针的指针和指针的引用修改传递给方法的指针,以便更好的使用它.(这里说的指针的指针不是一个二维数组) 为什么需要使用它们 当我们把一个指针做为参数传一个方法时,其实是把指针的复本传递给了方 ...
- 防止 JavaScript 自动插入分号
JavaScript语言有一个机制:在解析时,能够在一句话后面自动插入一个分号,用来修改语句末尾遗漏的分号分隔符. 然而,由于这个自动插入的分号与JavaScript语言的另一个机制发生了冲突,即所有 ...
- Theano2.1.1-基础知识之准备工作
来源:http://deeplearning.net/software/theano/tutorial/index.html#tutorial 这里介绍的是使用theano的一些基础知识,虽然thea ...
- 基于DDD的.NET开发框架 - ABP日志Logger集成
返回ABP系列 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应 ...