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 ...
随机推荐
- Java中HashSet,HashMap和HashTable的区别
HashMap.HashSet.HashTable之间的区别是Java程序员的一个常见面试题目,在此仅以此博客记录,并深入源代码进行分析: 在分析之前,先将其区别列于下面 1:HashSet底层采用的 ...
- 产品经理技能之MRD的笔记之一
原文:http://www.woshipm.com/pmd/131946.html/comment-page-1 产品经理技能之MRD 一.MRD与BRD的不同之处 BRD:这么做有什么好处,并说明好 ...
- 您的项目引用了最新实体框架;但是,找不到数据链接所需的与版本兼容的实体框架数据库 EF6使用Mysql的技巧
转载至: http://www.cnblogs.com/Imaigne/p/4153397.html 您的项目引用了最新实体框架:但是,找不到数据链接所需的与版本兼容的实体框架数据库 EF6使用Mys ...
- 学习C++.Primer.Plus 7 函数
C++的返回值类型不能是数组 函数原型中的变量名相当于点位符,因此不要求提供变量名. void cheers(int); C++中不指定参数列表时就使用活力号: void saybye(...); 通 ...
- 如何在mac本上安装android sdk
众所周知的原因,google的很多网站在国内无法访问,苦逼了一堆天朝程序员,下是在mac本上折腾android 开发环境的过程: 一.先下载android sdk for mac 给二个靠谱的网址: ...
- 资源搜集:Git精品文章推荐,常年更新
以下放置的是搜集到的Git精品文章,常年更新: Git 常用命令详解(二) Git版本控制软件结合GitHub从入门到精通常用命令学习手册 Pro Git(中文版)
- Apache Shiro 使用手册(一)Shiro架构介绍 - kdboy - ITeye技术网站
转载 原文地址 http://kdboy.iteye.com/blog/1154644 一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理 ...
- 详解c++指针的指针和指针的引用
展示一下使用指针的指针和指针的引用修改传递给方法的指针,以便更好的使用它.(这里说的指针的指针不是一个二维数组) 为什么需要使用它们 当我们把一个指针做为参数传一个方法时,其实是把指针的复本传递给了方 ...
- 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...
- 将DBF文件导入Sqlserver数据库
项目中的问题:用户选择N个dbf文件导入sql2005数据库,由于每年dbf表结构都在变化,所以在sql2005中根本就不存在,需要每年根据dbf的结构自动建表.(文章来自http://blog.cs ...