题目描述

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_id​i​​ and w_iw​i​​ (1\le d_i,w_i\le 1\ 000\ 000\ 0001≤d​i​​,w​i​​≤1 000 000 000), separated by a single space, denoting respectively the length and height of the i^{th}i​th​​ 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.

第一个为一个整数,表示最少需要几张海报.

输入输出样例

输入样例#1:

5
1 2
1 3
2 2
2 5
1 4
输出样例#1:

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

  1. [POI 2008&洛谷P3467]PLA-Postering 题解(单调栈)

    [POI 2008&洛谷P3467]PLA-Postering Description Byteburg市东边的建筑都是以旧结构形式建造的:建筑互相紧挨着,之间没有空间.它们共同形成了一条长长 ...

  2. BZOJ1123或洛谷3469 [POI2008]BLO-Blockade

    BZOJ原题链接 洛谷原题链接 若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\). 若第\(i\)个点是割点,那么去掉这个点相关 ...

  3. 洛谷 P3478 [POI2008]STA-Station

    题目描述 The first stage of train system reform (that has been described in the problem Railways of the ...

  4. 洛谷 P3477 [POI2008]PER-Permutation 解题报告

    P3477 [POI2008]PER-Permutation 题目描述 Multiset is a mathematical object similar to a set, but each mem ...

  5. 洛谷P3478 [POI2008]STA-Station

    P3478 [POI2008]STA-Station 题目描述 The first stage of train system reform (that has been described in t ...

  6. 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)

    P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...

  7. 洛谷P3469[POI2008]BLO-Blockade

    题目 割点模板题. 可以将图中的所有点分成两部分,一部分是去掉之后不影响图的连通性的点,一部分是去掉之后影响连通性的点,称其为割点. 然后分两种情况讨论,如果该点不是割点,则最终结果直接加上2*(n- ...

  8. 洛谷 P3469 [POI2008]BLO-Blockade 题解

    一道经典的割点例题,用size数组记录该子树有多少个节点,sum是这棵搜索树上有多少个节点,sum*(n-sum-1)是将点删掉后的数对数量. #include<iostream> #in ...

  9. 「洛谷3469」「POI2008」BLO-Blockade【Tarjan求割点】

    题目链接 [洛谷传送门] 题解 很显然,当这个点不是割点的时候,答案是\(2*(n-1)\) 如果这个点是割点,那么答案就是两两被分开的联通分量之间求组合数. 代码 #include <bits ...

随机推荐

  1. @RequestMapping[转]

    转自 http://www.cnblogs.com/qq78292959/p/3760560.html#undefined 引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST. ...

  2. SpringBoot学习笔记(13)----使用Spring Session+redis实现一个简单的集群

    session集群的解决方案: 1.扩展指定server 利用Servlet容器提供的插件功能,自定义HttpSession的创建和管理策略,并通过配置的方式替换掉默认的策略.缺点:耦合Tomcat/ ...

  3. 浏览器解析,HTTP/HTTPS、TCP/IP、WebSocket协议

    浏览器相关 浏览器对同一个域名有连接数限制,大部分是 6. 浏览器指的是 Chrome.Firefox,而浏览器内核则是 Blink.Gecko,浏览器内核只负责渲染,GUI 及网络连接等跨平台工作则 ...

  4. canvas 连线曲线图封装

    $.fn.hChart=function (opt) { var setting=$.extend({ className:'', data:[] },opt); var tbody=this; va ...

  5. list 分页

    package com.jsz.peini.common.util; import java.util.ArrayList; import java.util.List; public class S ...

  6. Bedrock Linux 0.7.3 发布

    Bedrock Linux是一种元分发,允许用户利用其他通常互斥的Linux发行版的功能,并让它们无缝地一起工作.该项目发布了其0.7.x系列,Bedrock Linux 0.7.3的更新. 新的更新 ...

  7. [ZJOI2008]骑士(基环树,树形dp)

    [ZJOI2008]骑士 题目描述 Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的 ...

  8. 微信小程序踩坑记

    1:微信小程序之去掉横向滑动滚动条 /** 去除横向滚动条 */ ::-webkit-scrollbar { width: 0; height: 0; color: transparent; } 2: ...

  9. Oracle 切割字符查询

    Oracle 切割字符查询 select * from view_psbaseinfo where DECODE('410782001125,411100000043', '', NULL, '410 ...

  10. 二维码框架ZBarSDK的使用和自己定义二维码扫描界面方法

    假设你不知道ZBarSDK怎么用,请下载demo http://download.csdn.net/detail/u013686641/7858917 假设你已经配置好ZBarSDK .那么以下这个类 ...