CF-1107-D

先贴代码,后面证明

/*
    @description: cf-1107-D
    @author: universal42@163.com
    @solution: 暴力
*/
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LOCAL
#define cls ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define Mod 998244353
#define ll long long int
#define mset(a,b) memset(a,b,sizeof(a))
#define INF 1e9
const int maxn=5200+5;
int a[maxn][maxn];
int n;
void debug(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) cout<<a[i][j]<<" ";
        cout<<endl;
    }
}
bool check(int x){//判断x*x的子矩阵内所有元素是否相等,x是子矩阵长
    for(int i=1;i<=n;i+=x){
        for(int j=1;j<=n;j+=x){
            int t=a[i][j];
            for(int k=0;k<x;k++){
                for(int l=0;l<x;l++) if(a[i+k][j+l]!=t) return 0;
            }
        }
    }
    return 1;
}
int main() {
    cls;
#ifdef LOCAL
    freopen("in.in","r",stdin);
#endif // LOCAL
    cin>>n;
    string s;
    for(int i=1;i<=n;i++){
        //16进制转换为二进制
        cin>>s;
        int t;
        for(int j=n;j>=1;j-=4){
            t=(isdigit(s[(j-1)/4])?s[(j-1)/4]-'0':s[(j-1)/4]-'A'+10);
            for(int l=0;l<4;l++){
                a[i][j-l]=(t>>l)&1;
            }
        }
    }
    //debug();
    //暴力解法
    for(int i=n;i>1;i--){
        if(n%i==0){//是其因子
            if(check(i)){//x==i
                cout<<i<<endl;
                return 0;
            }
        }
    }
    cout<<1<<endl;
    return 0;
}
Author: universal42
Link: https://universal4s.github.io/2019/02/17/cf-1107-d/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.