HNU2019 Summer Training 3 E. Blurred Pictures
2 seconds
256 megabytes
standard input
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.
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.
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.
3
1 1
0 2
1 1
1
8
2 4
2 4
1 4
0 7
0 3
1 2
1 2
1 1
3
- 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的更多相关文章
- [Artoolkit] Marker Training
Link: Documentation About the Traditional Template Square Marker Limitations (重要) Traditional Templa ...
- 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) ...
- 2016 Multi-University Training Contests
2016 Multi-University Training Contest 1 2016 Multi-University Training Contest 2 2016 Multi-Univers ...
- 2016 Multi-University Training Contest 2 D. Differencia
Differencia Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 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) ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- 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 ...
- 2012 Multi-University Training Contest 9 / hdu4389
2012 Multi-University Training Contest 9 / hdu4389 打巨表,实为数位dp 还不太懂 先这样放着.. 对于打表,当然我们不能直接打,这里有技巧.我们可以 ...
- 2014 Multi-University Training Contest 9#11
2014 Multi-University Training Contest 9#11 Killing MonstersTime Limit: 2000/1000 MS (Java/Others) ...
- 2014 Multi-University Training Contest 9#6
2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...
随机推荐
- 你的梦想家居「GitHub 热点速览」
上周推荐的 ChatGPT 版小爱,不知道有哪些小伙伴回去尝试接入了呢?本周依旧由 2 个不错的 ChatGPT 延伸项目,一个是比 DeepL.Grammarly 更懂你的划词翻译 openai-t ...
- 对利用jsp模板编写登录、注册界面的方法言
使用模板的相关操作步骤详解 1.可以在相关的网站上面找相关的css或者js文件,下载到一个特定的文件夹里面,以备使用 2.然后,将存有相关代码的文件夹直接复制粘贴到web文件下,就会直接保存,可以根据 ...
- Python批量采集百度资讯文章,如何自定义采集日期范围
01 引言 大家好!蜡笔小曦有个朋友是做能源相关工作的,她想要有一个工具以天为单位持续地采集百度资讯中能源相关的文章进行留存和使用. 其中有个需求点是说能够自定义采集的开始日期和结束日期,这样更加灵活 ...
- 关于 manacher 的一个小细节
在该算法中,我们需要用到一个数组 hw[i] ,代表 i 的最大回文半径.而且这个半径不包括 i 本身(若串为 ccc 则 hw 为 1). 这时最终答案为最大的 hw 减一. 为什么要减一呢?最终的 ...
- uni-app云开发入门
云函数 首先创建一个uniapp项目,创建项目时选择启用uniCloud云开发. 创建项目成功后,按照下面的步骤进行开发. 创建云函数 1.关联云服务器 2.创建云函数 一个云函数可以看成是一个后 ...
- 领域驱动设计DDD应用与最佳实践
领域驱动设计(Domain Driven Design,简称:DDD)设计思想和方法论早在2005年时候就被提出来,但是一直没有重视和推荐使用,直到2015年之后微服务流行之后,再次被人重视和推荐使用 ...
- 算法题学习链路简要分析与面向 ChatGPT 编程
本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问. 声明:此图片由 MidJourney 生成 未经训练,不属于任何真实人物 大家好,我是小彭. 2023 开年 ...
- kubernetes 安装 Prometheus + Grafana
kubernetes 安装 Prometheus + Grafana kubernetes install Prometheus + Grafana 官网 Official website https ...
- [JavaScript]使页面内目标关键字高亮
1 源码 function keywordHighlighten(querySelector, key, bgColor){//文本关键字高亮 var doms = document.querySel ...
- python:调用内置函数
问题描述:尝试下博客园如何上传GIF # hzh 每天进步一点点 # 2022/5/13 17:24 import colorama import time import os colorama.in ...