Codeforces 22B Bargaining Table
http://www.codeforces.com/problemset/problem/22/B
题意:求出n*m的方格图中全是0的矩阵的最大周长
思路:枚举
1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstring> 5 #include<iostream> 6 int n,m,a[50][50],h[50][50]; 7 char s[500]; 8 int read(){ 9 int t=0,f=1;char ch=getchar(); 10 while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} 11 while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();} 12 return t*f; 13 } 14 int main(){ 15 n=read();m=read(); 16 for (int i=1;i<=n;i++){ 17 scanf("%s",s+1); 18 for (int j=1;j<=m;j++) 19 a[i][j]=s[j]-'0'; 20 } 21 for (int i=1;i<=n;i++) 22 for (int j=1;j<=m;j++){ 23 if (a[i][j]) continue; 24 if (i!=1&&a[i-1][j]==0) h[i][j]=h[i-1][j]+1; 25 else h[i][j]=1; 26 } 27 int ans=0; 28 for (int i=1;i<=n;i++) 29 for (int j=1;j<=m;j++) 30 if (a[i][j]==0) 31 { 32 int ll=1<<29; 33 for (int k=j;k>=1&&a[i][k]==0;k--){ 34 ll=std::min(ll,h[i][k]); 35 ans=std::max(ans,ll+j-k+1); 36 } 37 } 38 printf("%d\n",ans*2); 39 return 0; 40 }