1 条题解

  • 0
    @ 2026-2-28 16:46:58
    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=11;
    char a[maxn][maxn];
    int n,m,t;
    string s;
    
    bool chk(int x,int y){
        for(int i=1;i<=x+3;i++){
            for(int j=1;j<=y+3;j++){
                if(i==x||i==x+3||j==y||j==y+3){
                    if(a[x][y]=='1') return 0;               
                }else{
                    if(a[x][y]=='0') return 0;
                }
            }
        }
        return 1;
    }
    int main(){
        int t,n,m;
        string s;
        cin>>t;
        //
        while(t--){
            cin>>n>>m;
            //
            for(int i=1;i<=n;i++){
                cin>>s;
                for(int j=1;j<=m;j++){
                    a[i][j]=s[j-1];
                }
            }
            //
            bool is=0;
            for(int x=1;x<=n-3;x++){
                for(int y=1;y<=m-3;y++){
                    if(chk(x,y)){
                        cout<<"Yes"<<endl;
                        is=true;
                        break;
                    }
                    if(is==1) break;
                }
                if(is==1) break;
            }
            if(is==0) cout<<"No"<<endl;
        }
        return 0;
    }
    
    

    黑白方块(洛谷 B4040 普及-)(子矩阵问题)

    信息

    ID
    652
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    74
    已通过
    9
    上传者