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 ...
随机推荐
- Android 中布局设置导致的TextView不显示的问题
将TextView放入TableLayout中,设置TextView的Layout Witdh/Layout Height 为Wrap Content或其他大小,导致TextView内容无法显示,改为 ...
- js判断是否在微信浏览器中打开
用JS来判断,无论是android 还是iphone,ipad 都可以 function is_weixn(){ var ua = navigator.userAgent.toLowerCase(); ...
- Codevs 1910递归函数
1910 递归函数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 对于一个递归函数w(a, b, c). 如果a <= ...
- 微软职位内部推荐-SDEII_ ECO
微软近期Open的职位: SDE II SDE II Organization Summary: Engineering, Customer interactions & Online (EC ...
- logback + slf4j + jboss + spring mvc
logback.log4j.log4j2 全是以同一个人为首的团伙搞出来的(日志专业户!),这几个各有所长,log4j性能相对最差,log4j2性能不错,但是目前跟mybatis有些犯冲(log4j2 ...
- caffe的python接口学习(2):生成solver文件
caffe在训练的时候,需要一些参数设置,我们一般将这些参数设置在一个叫solver.prototxt的文件里面,如下: base_lr: 0.001 display: 782 gamma: 0.1 ...
- 如何对于几百行SQL语句进行优化?
1.最近在开发中遇到的一些关于几百行SQL语句做查询的问题,需要如何的解决优化SQL这确实是个问题,对于当下的ORM 框架 EF 以及其他的一些的开源的框架例如Drapper ,以及Sqlite-Su ...
- 十分钟掌握Activity的生命周期与启动模式
1. Activity的生命周期 正常情况下的Activity生命周期如下图所示(来自Android Developer): 当资源相关的系统配置变更时(比如设备屏幕方向改变,键盘可见性变化),会导致 ...
- 从零开始搭建架构实施Android项目
我们先假设一个场景需求:刚有孩子的爸爸妈妈对用照片.视频记录宝宝成长有强烈的意愿,但苦于目前没有一款专门的手机APP做这件事.A公司洞察到市场需求,要求开发团队尽快完成Android客户端的开发.以下 ...
- 青瓷引擎使用心得——修改引擎的loading界面
一. 修改引擎的Loading界面之使用进度条显示1. 双击打开引擎包中的lib/qc-loading-debug.js,如下图所示: 2. 只需要修改qici.init函数即可改变loading界面 ...