Codeforces 22B Bargaining Table

Posted GFY

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于Codeforces 22B Bargaining Table的主要内容,如果未能解决你的问题,请参考以下文章

mysql查询随机和desc

oracle 两行及多行关键字相同数据并为一条数据

Kubernetes 错误汇总(持续更新)

Azure Functions 界面弹出错误消息

替换 RDD 的一些元素

如何访问二维数组的元素?