题目描述

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. SLAM概念学习之特征图Feature Maps

    特征图(或者叫地标图,landmark maps)利用参数化特征(如点和线)的全局位置来表示环境.如图1所示,机器人的外部环境被一些列参数化的特征,即二维坐标点表示.这些静态的地标点被观测器(装有传感 ...

  2. 前端压缩图片,前端压缩图片后转换为base64.

    今天利用一上午研究了一下前端如何将5m左右的照片转换base64大小为 100k以内! 有两个链接:https://www.cnblogs.com/007sx/p/7583202.html :http ...

  3. Sublime Text编辑器配置Python解释器简易教程

    前天在微信上遇到一个小伙伴问我一个关于Sublime text配置Python解释器的问题,可能是初学者,对这方面还不是很懂,想使用快捷键但是徒劳一场,因为缺少Python解释器,直接按下快捷键Ctr ...

  4. 路飞学城Python-Day14(practise)

    本章总结 练习题 1.logging模块有几个日志级别? 5个,按级别从高到低分别是 CRITICAL(灾难)>ERROR(错误)>WARNING(警示)>INFO(信息)>D ...

  5. vue循环遍历给div添加id

    html部分 <div class="img-preview" v-for="(img,i) of list" :key="img.imageK ...

  6. 简洁的MVC思想框架——Nancy(环境配置与Get操作)

    Nancy官网——https://github.com/NancyFx/Nancy 概述:Nancy是一个开源的Web轻型框架内核符合MVC思想,有开发方便,路由简单的特点,而且功能齐全 起步:Hel ...

  7. windows下安装redis以及测试 Window 下安装

    下载地址:https://github.com/dmajkic/redis/downloads. 下载到的Redis支持32bit和64bit.根据自己实际情况选择,将64bit的内容cp到自定义盘符 ...

  8. HDU 4965 Fast Matrix Calculation 矩阵乘法 乘法结合律

    一种奇葩的写法,纪念一下当时的RE. #include <iostream> #include <cstdio> #include <cstring> #inclu ...

  9. sqoop从mysql导入到hdfs出现乱码问题

    最近把hive元数据库的快照数据导入到hdfs中,以便对历史的元数据进行查询. 命令如下: sqoop import -D mapred.job.queue.name=do.production -- ...

  10. C++的hashmap和Java的hashmap

    C++里面是这样的:typedef std::unordered_map<std::string,std::string> stringmap; std::unordered_map< ...