区间操作--B - Blurred Pictures Gym - 102465B

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.
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<bits/stdc++.h>
using namespace std;
int l[100100];
int r[100100];
int main()
{
    int ans=1;//最小为1(题目保证存在)
    int n;
    cin>>n;
    for(int i=0; i<n; i++) cin>>l[i]>>r[i];
    for(int i=0; i<n; i++)
    {
        while(1)
        {
            if(r[i]-l[i]<ans) break;//如果小于ans的话,直接下一行即可
            if(i+ans>=n) break;//如果超出下边界,结束
            int endd=i+ans;//记录最终行
            int ft=max(l[i],l[endd]);//判断第一行和最后一行哪一个起始点靠后
            if(ft+ans<=r[i]&&ft+ans<=r[endd]) ans++;//如果第一行起点加上ans并且最后一行起点加上ans小于这两行的终点,ans++;
            else break;//如果有一个不小于,下一行
        }
    }
    cout<<ans<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JdiLfc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值