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

5
1 2
1 3
2 2
2 5
1 4

Sample Output

4

HINT

 

Source

 

[Submit][Status][Discuss]

分析

单调栈

代码

 /*<--- 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的更多相关文章

  1. bzoj 1113 [Poi2008]海报PLA 单调栈

    [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1304  Solved: 896[Submit][Status][Dis ...

  2. 1113: [Poi2008]海报PLA

    1113: [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 765  Solved: 466[Submit][Status ...

  3. BZOJ——T 1113: [Poi2008]海报PLA

    http://www.lydsy.com/JudgeOnline/problem.php?id=1113 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: ...

  4. BZOJ1113 Poi2008 海报PLA【单调栈】【水】

    BZOJ1113 Poi2008 海报PLA Description N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们. Input 第一行给出数字N,代表有N个矩形.N在[1,250 ...

  5. bzoj1113: [Poi2008]海报PLA

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  6. BZOJ1113 [Poi2008]海报PLA 【分治 + 线段树】

    题目链接 BZOJ1113 题解 显然只与高有关,每次选择所有海报中最低的覆盖所有海报,然后分治两边 每个位置会被调用一次,复杂度\(O(nlogn)\) \(upd:\)智障了,,是一道\(O(n) ...

  7. [POI2008]海报PLA

    Description N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们. Input 第一行给出数字N,代表有N个矩形.N在[1,250000] 下面N行,每行给出矩形的长与宽.其值 ...

  8. BZOJ1113 海报PLA

    好像是很古老的题?现在BZOJ上找不到该题,所以没有提交. 1113: [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 8 ...

  9. 【BZOJ-1113】海报PLA 单调栈

    1113: [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 896  Solved: 573[Submit][Status ...

随机推荐

  1. Python自动补全

    转自:http://blog.linuxeye.com/324.html Python自动补全有vim编辑下和python交互模式下,下面分别介绍如何在这2种情况下实现Tab键自动补全. 一.vim ...

  2. jquery无缝间歇向上滚动(间断滚动)

    jquery无缝间歇向上滚动 JS部份 $(function(){ var $this = $(".renav"); var scrollTimer; $this.hover(fu ...

  3. php 中的curl

    ① curl上传文件 <?php $postData=array( 'name'=>'123', 'upload'=>'@E:/wamp/www/function/result.zi ...

  4. BZOJ 1251: 序列终结者

    1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MB Submit: 3773  Solved: 1579 [Submit][Status][Dis ...

  5. Cordova - 使用Cordova开发iOS应用实战3(添加Cordova控制台插件)

    Cordova - 使用Cordova开发iOS应用实战3(添加Cordova控制台插件) 前文介绍了通过 Safari 的 Web检查器,可以看到控制台输出的信息.但有时这样调试代码不太方便,如果在 ...

  6. ImageMagick常用指令详解

    Imagemagick常用指令 (ImageMagick--蓝天白云) (ImageMagick官网) (其他比较有价值的IM参考) (图片自动旋转的前端实现方案) convert 转换图像格式和大小 ...

  7. 发布了Android的App,我要开源几个组件!

    做了一款App,本来是毕业设计但是毕业的时候还没有做完,因为大部分时间都改论文去了,你们都懂的.现在毕业了在工作之余把App基本上做完了.为什么说基本上呢,因为我觉得还有很多功能还没实现,还要很多bu ...

  8. Java实现生产者和消费者

    生产者和消费者问题是操作系统的经典问题,在实际工作中也常会用到,主要的难点在于协调生产者和消费者,因为生产者的个数和消费者的个数不确定,而生产者的生成速度与消费者的消费速度也不一样,同时还要实现生产者 ...

  9. Python2.3-原理之语句和语法

    此节来自于<Python学习手册第四版>第三部分 一.python语句简介(第10章) 1.首先记得一个概念:a.程序由模块构成:b.模块包含语句:c.语句包含表达式:d.表达式建立并处理 ...

  10. MVVM小记

    这篇小记源自于codeproject上的一篇文章 http://www.codeproject.com/Articles/100175/Model-View-ViewModel-MVVM-Explai ...