其他分享
首页 > 其他分享> > 最大正方形

最大正方形

作者:互联网

#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, ans;
int a[105][105], sum[105][105];

int main()
{
    int size;
    scanf("%d%d", &n, &m);
    size = min(n, m);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            scanf("%d", &a[i][j]);
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            for (int l = 1; l <= size; l++)
            {
                int rx = i + l - 1;
                int ry = j + l - 1;
                if (rx > n || ry > m || sum[rx][ry] - sum[rx][j - 1] - sum[i - 1][ry] + sum[i - 1][j - 1] != l * l)
                    break;
                if (ans < l)
                    ans = l;
            }
        }
    }
    printf("%d", ans);
}

标签:最大,int,sum,rx,ry,正方形,ans,105
来源: https://www.cnblogs.com/Atoli-Sego/p/16539525.html