E. Blurred Pictures
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Damon loves to take photos of the places he visits during his travels, to put them into frames. All of his photos are in a square format of N×N pixels. He brought back beautiful pictures of the many monuments in Paris, such as the Eiffel Tower or the Louvre, but unfortunately, when he got back home, he realized that all his pictures were blurred on the edges. Looking closely, Damon realizes that he can easily distinguish the blurred pixels from the "good" (i.e., non-blurred) ones and that, luckily, all the non-blurred pixels are connected in such a way that any horizontal or vertical line drawn between two non-blurred pixels goes only through non-blurred pixels. In order to get the best from his failed pictures, he decides to cut out the biggest possible picture without any blurred pixel from each of his photos. And since his frames are all squares, for aesthetic reasons, the cut-out pictures have to be squares too. Damon does not want his pictures to be tilted so he wants the sides of the cut-outs to be parallel to the sides of the original picture.

Input

The input comprises several lines, each consisting of integers separated with single spaces:

  • The first line contains the length N, in pixels, of the input photo;
  • Each of the next N lines contains two integers ai and bi , the indices of the first (ai)and the last (bi) non-blurred pixel on the i-th line.
  • 0<N≤100000,
  • 0≤ai≤bi<N.
Output

The output should consist of a single line, whose content is an integer, the length of the largest square composed of non-blurred pixels inside the picture.

Examples
input
3
1 1
0 2
1 1
output
1
input
8
2 4
2 4
1 4
0 7
0 3
1 2
1 2
1 1
output
3
Note
  • In the input picture, each row and each column has at least one non-blurred pixel.
  • In any two consecutive lines, there are at least two non-blurred pixels in the same column.

代码实现:

#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
const int N=2e5+5;
int l[N],r[N];
signed main(){
int n;
cin>>n;
//题目保证最小为1
int res=1;
//输入每行的左端点和右端点
for(int i=1;i<=n;i++)cin>>l[i]>>r[i];
for(int i=1;i<=n;i++){
while(1){
//如果当前行的长度都小于res,直接换下一行
if(r[i]-l[i]<res)break;
//如果当前行向下越界了,直接返回
if(res+i>n)break;
//记录最终行
int ed=res+i;
//判断第一行和最后一行起始点哪个靠后
int bg=max(l[i],l[ed]);
//如果bg加res小于等第一行右端点且bg加res小于等于最终行右端点,则表示当前行可取,res++,继续往下判断
if(bg+res<=r[i]&&bg+res<=r[ed])res++;
//否则表示当前行已经无法继续向下判断了
else break;
}
}
cout<<res<<endl;
return 0;
}

HNU2019 Summer Training 3 E. Blurred Pictures的更多相关文章

  1. [Artoolkit] Marker Training

    Link: Documentation About the Traditional Template Square Marker Limitations (重要) Traditional Templa ...

  2. hdu 4946 2014 Multi-University Training Contest 8

    Area of Mushroom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. 2016 Multi-University Training Contests

    2016 Multi-University Training Contest 1 2016 Multi-University Training Contest 2 2016 Multi-Univers ...

  4. 2016 Multi-University Training Contest 2 D. Differencia

    Differencia Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  5. 2016 Multi-University Training Contest 1 G. Rigid Frameworks

    Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  7. The Solution of UESTC 2016 Summer Training #1 Div.2 Problem C

    Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/C Description standard input/output After ...

  8. 2012 Multi-University Training Contest 9 / hdu4389

    2012 Multi-University Training Contest 9 / hdu4389 打巨表,实为数位dp 还不太懂 先这样放着.. 对于打表,当然我们不能直接打,这里有技巧.我们可以 ...

  9. 2014 Multi-University Training Contest 9#11

    2014 Multi-University Training Contest 9#11 Killing MonstersTime Limit: 2000/1000 MS (Java/Others)   ...

  10. 2014 Multi-University Training Contest 9#6

    2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...

随机推荐

  1. 基于 RocketMQ Connect 构建数据流转处理平台

    本文作者:周波,阿里云智能高级开发工程师, Apache RocketMQ Committer . 01 从问题中来的RocketMQ Connect 在电商系统.金融系统及物流系统,我们经常可以看到 ...

  2. SQL server分页的三种方法

    一.Entity Framework的Linq语句的分页写法: var datacount = test.OrderBy(t => t.testID) .Skip(pageSize * (pag ...

  3. Three.js 进阶之旅:物理效果-3D乒乓球小游戏 🏓

    声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 摘要 本文在专栏上一篇内容<Three.js 进阶之旅:物理效果-碰撞和声 ...

  4. Tomcat启动JSP项目,搞起来了

    虽然有点复古,但是还是有很多小伙伴在使用的,小编来一篇保姆级教程 1.用idea打开jsp项目 2.添加tomcat配置 3.点击后会出现配置框,这里画框的地方都选上,版本选择1.8,其他的信息内容默 ...

  5. Serial port

    前言 ​ 使用qt开发一款简易串口助手. ​ 目标: 1. 实现正常串口通信. 2. 能够传输AT指令.(需要注意回车符) github仓库地址:shadow-wd/Serial-port-assis ...

  6. ACM-CodeForces-#685(Div.2)

    好久没见过CF有这么水的contest了,蒟蒻赶紧找找自信 A. Subtract or Divide #include<iostream> using namespace std; in ...

  7. vue:路由守卫

    路由守卫 作用:对路由进行权限控制 配置路由守卫应在暴露前配置 分类:全局守卫.独享守卫.组件内守卫 首先先给需要鉴权的路由设置好meta配置项. meta配置项:是vue-router中的一个对象, ...

  8. 联想拯救者Y9000P 2023版 双系统ubuntu安装nvidia显卡驱动、cuda及cudnn简明教程

    前言 对于从事机器学习.深度学习.图像处理.自然语言处理等科研与工作的小伙伴们,ubuntu系统是一个不错的选择,本人前几天入手拯救者y9000p 2023版本,配置为:RTX4060 16G 13代 ...

  9. oracle删除一张表后,索引,同义词,视图,约束会被删除么

    问题描述:看到有一道题,说删除一张表之后,什么会被关联删除 进行测试,看看一张表什么会被关联删除,进行scoot下的EMP进行测试 一.创建测试需求用例 表结构: SQL> desc emp; ...

  10. 基于Switching的 恒虚警率检测算法

    转发和使用请注明来源,以下为本人精心整理,还请尊重本人劳动成果与产权!由于本人现有知识和能力有限,如存在错误之处请指正!下面为正文内容: 1.S-CFAR检测算法(Switching,开关CFAR) ...