洛谷 P3467 [POI2008]PLA-Postering
题目描述
All the buildings in the east district of Byteburg were built in accordance with the old arbitecture:
they stand next to each other with no spacing inbetween.
Together they form a very long chain of buildings of diverse height, extending from east to west.
The mayor of Byteburg, Byteasar, has decided to have the north face of the chain covered with posters.
Byteasar ponders over the minimum number of posters sufficient to cover the whole north face.
The posters have rectangular shape with vertical and horizontal sides.
They cannot overlap, but may touch each other, i.e. have common points on the sides.
Every poster has to entirely adjoin the walls of certain buildings and the whole surface of the north face has to be covered.
Task Write a programme that:
reads the description of buildings from the standard input, determines the minimum number of posters needed to entirely cover their north faces, writes out the outcome to the standard output.
Byteburg市东边的建筑都是以旧结构形式建造的:建筑互相紧挨着,之间没有空间.它们共同形成了一条长长的,从东向西延伸的建筑物链(建筑物的高度不一).Byteburg市的市长Byteasar,决定将这个建筑物链的一侧用海报覆盖住.并且想用最少的海报数量,海报是矩形的.海报与海报之间不能重叠,但是可以相互挨着(即它们具有公共边),每一个海报都必须贴近墙并且建筑物链的整个一侧必须被覆盖(意思是:海报需要将一侧全部覆盖,并且不能超出建筑物链)
输入输出格式
输入格式:
The first line of the standard input contains one integer nn (1\le n\le 250\ 0001≤n≤250 000), denoting the number of buildings the chain comprises of.
Each of the following nn lines contains two integers d_idi and w_iwi (1\le d_i,w_i\le 1\ 000\ 000\ 0001≤di,wi≤1 000 000 000), separated by a single space, denoting respectively the length and height of the i^{th}ith building in the row.
第一行为一个整数n(1≤n≤250000),表示有n个建筑,接下来n行中,第i行表示第i个建筑物的宽di与高wi(1≤di,wi≤1 000 000 000),中间由一个空格隔开
输出格式:
The first and only line of the standard output should contain one integer, the minimum number of rectangular posters that suffice to cover the north faces of the buildings.
第一个为一个整数,表示最少需要几张海报.
输入输出样例
5
1 2
1 3
2 2
2 5
1 4
4
说明
题目简述:N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们.
感谢@__乱世魇华 提供翻译
思路:这个题目难在读题,用单调栈维护一下就好了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 250005
using namespace std;
long long n,top,ans;
long long a[MAXN],stack[MAXN];
int main(){
scanf("%lld",&n);
for(int i=;i<=n;i++){
int x;
scanf("%d%lld",&x,&a[i]);
}
for(int i=;i<=n;i++){
while(top&&stack[top]>a[i])
top--;
if(stack[top]==a[i])
ans++;
stack[++top]=a[i];
}
printf("%lld\n",n-ans);
return ;
}
洛谷 P3467 [POI2008]PLA-Postering的更多相关文章
- [POI 2008&洛谷P3467]PLA-Postering 题解(单调栈)
[POI 2008&洛谷P3467]PLA-Postering Description Byteburg市东边的建筑都是以旧结构形式建造的:建筑互相紧挨着,之间没有空间.它们共同形成了一条长长 ...
- BZOJ1123或洛谷3469 [POI2008]BLO-Blockade
BZOJ原题链接 洛谷原题链接 若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\). 若第\(i\)个点是割点,那么去掉这个点相关 ...
- 洛谷 P3478 [POI2008]STA-Station
题目描述 The first stage of train system reform (that has been described in the problem Railways of the ...
- 洛谷 P3477 [POI2008]PER-Permutation 解题报告
P3477 [POI2008]PER-Permutation 题目描述 Multiset is a mathematical object similar to a set, but each mem ...
- 洛谷P3478 [POI2008]STA-Station
P3478 [POI2008]STA-Station 题目描述 The first stage of train system reform (that has been described in t ...
- 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)
P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...
- 洛谷P3469[POI2008]BLO-Blockade
题目 割点模板题. 可以将图中的所有点分成两部分,一部分是去掉之后不影响图的连通性的点,一部分是去掉之后影响连通性的点,称其为割点. 然后分两种情况讨论,如果该点不是割点,则最终结果直接加上2*(n- ...
- 洛谷 P3469 [POI2008]BLO-Blockade 题解
一道经典的割点例题,用size数组记录该子树有多少个节点,sum是这棵搜索树上有多少个节点,sum*(n-sum-1)是将点删掉后的数对数量. #include<iostream> #in ...
- 「洛谷3469」「POI2008」BLO-Blockade【Tarjan求割点】
题目链接 [洛谷传送门] 题解 很显然,当这个点不是割点的时候,答案是\(2*(n-1)\) 如果这个点是割点,那么答案就是两两被分开的联通分量之间求组合数. 代码 #include <bits ...
随机推荐
- hiho151周*
题目链接 题目大意:依次在给定的三维坐标上垒方块,对于一个新的坐标需满足两个条件 1:六个方向有相邻的方块或者z==1[题目说明了初始状态是:所有z==0的位置都有方块] 2:该位置存在一条到无穷远处 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- ActiveMQ学习笔记(17)----Message高级特性(一)
1. Messaage Properties ActiveMQ支持很多消息属性,具体可以参考 http://activemq.apache.org/activemq-message-propertie ...
- QT+OpenCV进行图像采集最小时延能够达到20ms
得到“算法高性能”项目的支持,目前成功地在Win10上运行WB2,感觉目前的代码速度慢.响应慢.CPU占用比例高.这种情况下3399上能够运行,说明这个平台已经是很强的了.下一步,首先在Windows ...
- Uncaught TypeError: Cannot read property 'offsetTop' of undefined at VueComponent.handleScroll
mounted() { window.addEventListener("scroll", this.handleScroll); }, beforeDestroy() { win ...
- nginx 多级7层代理安装配置
编译安装 yum install zlib-devel -y wget https://nginx.org/download/nginx-1.15.12.tar.gz tar -zxf nginx-1 ...
- syn攻击原理与防护措施
何为syn攻击? 先普及下tcp3次握手的知识,在TCP/IP中,tcp协议提供可靠的socket连接服务,通过3次握手建立可靠连接. tcp3次握手过程: 第一阶段:某终端向服务器发送syn(syn ...
- 紫书 例题 11-2 UVa 1395(最大边减最小边最小的生成树)
思路:枚举所有可能的情况. 枚举最小边, 然后不断加边, 直到联通后, 这个时候有一个生成树.这个时候,在目前这个最小边的情况可以不往后枚举了, 可以直接更新答案后break. 因为题目求最大边减最小 ...
- Solr教程--官方自带数据的三个练习及讨论翻译版本
Solr教程 在你开始之前 解压Solr 练习1:索引Techproducts示例数据 在SolrCloud模式下启动Solr 索引技术产品数据 基本搜索 练习1总结 练习2:修改架构和索引影片数据 ...
- "duplicate symbol for architecture i386" 解决的方法
我在写项目的过程中,碰到了这个错误,我在网上查了一下,发现这个错误的原因是,project里面有反复的类. 解决方式:找到反复的类,然后删除掉就好了. 分析一下, 如图. 能够看出, 错误类型是 du ...