luogu2701

和上一道一样,只不过换成正方形罢了

#include<bits/stdc++.h>
using namespace std;
int x,y,ans=0,n,highest,lowest;
struct one{int x,y;};
one e[10010];
bool cmp(one aa,one bb){return aa.x<bb.x;}
bool dmp(one aa,one bb){return aa.y<bb.y;}
int main()
{
    //freopen("xf.in","r",stdin);
    //freopen("xf.out","w",stdout);
    scanf("%d",&x);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&e[i].x,&e[i].y);
    sort(e+1,e+n+1,cmp);
    e[n+1].x=x+1;e[0].x=0;
    for(int i=1;i<=n;i++)
    {
        highest=x;lowest=1;
        for(int j=i+1;j<=n+1;j++)
        {
            if(e[j].x==e[i].x)continue;
            ans=max(ans,min(highest-lowest+1,e[j].x-e[i].x-1));
            if(e[j].y>=e[i].y)highest=min(highest,e[j].y-1);
            if(e[j].y<=e[i].y)lowest=max(lowest,e[j].y+1);
            if(highest-lowest+1<=ans)break;
        }
    }
    for(int i=n;i>=1;i--)
    {
        highest=x;lowest=1;
        for(int j=i-1;j>=0;j--)
        {
            if(e[j].x==e[i].x)continue;
            ans=max(ans,min(highest-lowest+1,e[i].x-e[j].x-1));
            if(e[j].y>=e[i].y)highest=min(highest,e[j].y-1);
            if(e[j].y<=e[i].y)lowest=max(lowest,e[j].y+1);
            if(highest-lowest+1<=ans)break;
        }
    }
    e[0].y=0;e[n+1].y=x+1;sort(e+1,e+n+1,dmp);
    for(int i=1;i<=n+1;i++)ans=max(e[i].y-e[i-1].y-1,ans);
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2020-08-29 11:35  mybing  阅读(102)  评论(0编辑  收藏  举报