Thứ Sáu, 13 tháng 5, 2022

AREA0 C++

#include <bits/stdc++.h>
using namespace std;

int n,m;
int a[1000][1000],b[1000][1000], f[1000][1000];

void nhap()
{
    scanf("%d%d",&m,&n);
    for (int i=1; i<=m; i++){
            for (int j=1; j<=n; j++) scanf("%d",&a[i][j]);
    }
}

void tinh_f()
{
    for (int i=1; i<=m; i++){
        for (int j=1; j<=n; j++)
            f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]+a[i][j];
    }
}

bool check(int i, int j, int x, int y){
    int s=(f[x][y]-f[i-1][y]-f[x][j-1]+f[i-1][j-1]);
    if (s==0) return true;
    else return false;
}

void tim_hcn(int i,int j)
{
    int y=j;
    while(y<n&&check(i,j,i,y+1))y++;
    b[i][j]=(y-j+1);
    for (int x=i+1; x<=m; x++)
    {
         while(y>=j&&!check(i,j,x,y)) y--;
         if (y<j) break;
         b[i][j]=max(b[i][j],(x-i+1)*(y-j+1));
    }
}
void giai()
{
    for (int i=1; i<=m; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (a[i][j]==1) b[i][j]=0;
            else tim_hcn(i,j);
            printf("%d ",b[i][j]);
        }
        printf("\n");
    }
}

 
int main()
{
    freopen("area0.inp","r",stdin);
        freopen("area0.out","w",stdout);
    nhap();
    tinh_f();
    giai();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.