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 ...
随机推荐
- JavaWeb笔记第一弹
一.MYSQL的安装 1.MYSQL的安装 可以去官网找到与自身计算机向对应的版本进行下载 网址如下: MySQL :: Download MySQL Community Server 2.MYSQL ...
- Python学习笔记--异常+模块+包
异常的捕获 基本语法: 示例: 捕获指定异常 基本语法:--必写 示例: 捕获多个异常 示例: 捕获所有异常 示例: 异常else--可写可不写 示例: 异常finally(无论是否出现异常,都会去执 ...
- 关于两行代码让我时间无限拉长这件事------mainServlet
在再一次尝试实现增删改查的功能时,出现了一些BUG,修改功能一直实现不了,查了好久的资料,这才发现问题 如上图所示,这个Servlet里面定义的方法,虽然很短,但是重要的很奥,改了好久都没注意到这个问 ...
- Activiti7开发(二)-流程定义
目录 1.部署流程模型为流程定义 2.挂起/激活流程定义 3.删除流程定义 4.查询流程定义 5.上传并部署流程定义 6.查看流程模型 1.部署流程模型为流程定义 @PostMapping(value ...
- 我用 Laf 三分钟写了一个专属 ChatGPT ,Laf 创始人:明天来上班!
起因 故事是这样的,一个月黑风高的夜晚,我掏出手机像往常一样打开朋友圈. 一开始我是不相信的,直到我(快速的) --> 打开 laf --> 创建应用 --> 新建云函数 --> ...
- day07-SpringBoot接收参数相关注解
SpringBoot接收参数相关注解 1.基本介绍 SpringBoot接收客户端提交数据/参数会使用到相关注解 详解@PathVariable.@RequestHeader.@ModelAttrib ...
- Spring Data Solr 对 Solr 的增删改查实例
Spring Data Solr 就是为了方便 solr 的开发研制的一个框架,其底层是对 SolrJ(官方 API)的封装 一.环境搭建 第一步:创建 Maven 项目(springdatasolr ...
- GO实现Redis:GO实现Redis协议解析器(2)
本文实现Redis的协议层,协议层负责解析指令,然后将指令交给核心database执行 echo database用来测试协议层的代码 https://github.com/csgopher/go-r ...
- VUE中的next({ ...to, replace: true })
beforeEach((to, from, next) => { next('/logon') } 上面这串代码我们可以看成为 beforeEach((to, from, next) => ...
- ACM-NEFUOJ-汉诺塔问题
P200汉诺塔 #include<bits/stdc++.h> using namespace std; int main() { int n,i; long long s[40]; s[ ...