题目描述

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 ;
}

最新文章

  1. 在Mac中像Windows一样查看Tomcat控制台信息
  2. 解决使用osgModeling的Loft生成管子时的bug(续)
  3. 【BZOJ-4547】小奇的集合 矩阵乘法 + 递推
  4. matlab中动态绘图并保存为视频的小例子
  5. json深度详解及org.json库
  6. Asp.Net Cookie的清除
  7. HDU1050(Moving Tables:贪心算法)
  8. poj1611 简单并查集
  9. Database Go and JSON
  10. ORACLE数据库常见问题汇总
  11. 消除Switch...Case的过程
  12. windows全系列激活脚本-改良版.cmd
  13. PHPOffice/PHPExcel生成省市区三级联动的excel表格
  14. spring boot 文件上传大小限制
  15. CAN总线疑惑与解答
  16. oracle 创建create user 及授权grant 查看登陆的用户
  17. [原创]php任务调度器 hellogerard/jobby
  18. maven安装,maven命令行使用
  19. 虚拟机如何设置外网ip
  20. 【HDU4303】Hourai Jeweled

热门文章

  1. hiho 1604 - 股票价格,思维题
  2. POJ 1990 MooFest【 树状数组 】
  3. swift语言点评一
  4. ZBrush功能特性之变形
  5. plsql 查询历史执行语句
  6. 解决com.mysql.jdbc.PacketTooBigException: Packet for query is too large问题
  7. C++ STL rope介绍----可持久化平衡树
  8. 基础命令:chown
  9. 华为P30系列新增“无线投屏”功能
  10. Vue style里面使用@import引入外部css, 作用域是全局的解决方案