Largest Allowed Area

题目:Largest Allowed Area

Refused
Refused
数据:

2 
10 20 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1  
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
20 10 
1 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 1 1 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
#include <bits/stdc++.h>

using namespace std;
const int  maxn=1010;
int a[maxn][maxn],dis[maxn][maxn];
int n,m;
bool read(int &num)
{
   char in;
   bool IsN=false;
   in=getchar();
   if(in==EOF)  return false;
   while(in!='-'&&(in<'0'||in>'9'))  in=getchar();\
   if(in=='-')
   {
      IsN=true;
      num=0;
   }
   else
   {
      num=in-'0';
   }
   while(in=getchar(),in>='0'&&in<='9')
   {
      num*=10,num+=in-'0';
   }
   if(IsN)  num=-num;
   return true;
}
int Judage(int i,int j,int d)
{
    int l=1,r=d,mid,ans=1;
    while(l<=r)
    {
       int mid=(l+r)/2;
       if(dis[i][j]-dis[i-mid][j]-dis[i][j-mid]+dis[i-mid][j-mid]<=1)
       {
         l=mid+1;
         ans=mid;
       }
       else
       {
          r=mid-1;
       }
    }
    return ans;
}
int main()
{
    int T;
    read(T);
    while(T--)
    {
        read(n);
        read(m);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
               read(a[i][j]);
               dis[i][j]=dis[i-1][j]+dis[i][j-1]-dis[i-1][j-1]+a[i][j];
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
               int d=min(i,j);
               int t=Judage(i,j,d);
               ans=max(ans,t);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

 

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页