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 ...
随机推荐
- js对象定义
JS中的对象定义方式,跟服务端,还是有很大差别的! 现在来说一下JS类的定义 工厂模式 function creatHeven(name,age){ var temp =new Object(); t ...
- Java 8特性探究(1):通往lambda之路与 lambda表达式10个示例
本文由 ImportNew 函数式接口 函数式接口(functional interface 也叫功能性接口,其实是同一个东西).简单来说,函数式接口是只包含一个方法的接口.比如Java标准库中的ja ...
- ItemIndex
ItemIndex一般是列表的一个属性,比如TCombobox和TListBox都有,表示当前选中的项(Item)的下标(Index),如果没有选中,那它是-1,所以一般判断TCombox或TList ...
- AngularJS中的缓存
欢迎大家指导与讨论 : ) 缓存篇 一个缓存就是一个组件,它可以透明地储存数据,以便以后可以更快地服务于请求.多次重复地获取资源可能会导致数据重复,消耗时间.因此缓存适用于变化性不大的一些数据,缓存能 ...
- STM32 控制红外线收发
买了一块STM32的板子,这次需要将IR的code移植到STM32上面,因为STM32成本比树莓派低得多,所以 一些简单的外设挂在STM32上就行了. 我买的板子的型号是STM32F103C8T6,价 ...
- 20145222GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 实践代码example.c #include<stdio.h> short addend1 = 1; static int addend2 = 2; const ...
- 我这样理解js里的this
关于this,是很多前端面试必考的题目,有时候在网上看到这些题目,自己试了一下,额,还真的错了!在实际开发中,也会遇到 this 的问题(虽然一些类库会帮我们处理),例如在使用一些框架的时候,例如:k ...
- 如何用 fiddler 捕获 https 请求
安装完 Fiddler 后,我们每次打开浏览器输入 url,Fiddler 便会捕获到我们的 http 请求(Fiddler 是以代理 web 服务器的形式工作的,它使用代理地址:127.0.0.1, ...
- Javascript的精华啊【如果以后我看到了或者想到了再继续补吧】
我不过略有一些讨人喜欢的地方而已,怎么会有什么迷人的魔力呢? 一.语法 JS只有一个数字类型,64位浮点数,所以1和1.0是相同的.为什么这么设计:防止短整型的溢出. 二.对象 1.通常将一个对象的值 ...
- 学习SQLite之路(四)
20160621 更新 参考: http://www.runoob.com/sqlite/sqlite-tutorial.html 1. SQLite alter命令:不通过执行一个完整的转储和数 ...