https://www.acwing.com/problem/content/161/

思路:横轴暴力枚举,竖轴KMP算法求循环节

#include <bits/stdc++.h>

using namespace std;
const int N=10000+10,M=80;
int n,m;
char s[N][M];
bool st[M];

int net[N];

int main()
{

   cin>>n>>m;

   for(int i=1;i<=n;i++){
       cin>>s[i];
       for(int j=1;j<=m;j++){
           for(int k=j;k<m;k+=j){
               for(int u=0;u<j&&u+k<m;u++){
                   if(s[i][u]!=s[i][u+k]) st[j]=1;
               }
           }
       }


   }

    int wid;

    for(int i=1;i<=m;i++){
        if(st[i]==0){
            wid=i;
            break;
        }
    }
//    cout<<wid<<endl;
    //cout<<"222"<<endl;
    for(int i=1;i<=n;i++) s[i][wid]='\0';

    int hight;

    for(int i=2,j=0;i<=n;i++){
        while(j && strcmp(s[i],s[j+1])) j=net[j];
        if(!strcmp(s[i],s[j+1])) j++;
        net[i]=j;
    }
    hight=n-net[n];
  

    cout<<hight*wid<<endl;
    return 0;
}

 posted on 2019-08-09 09:55  谁是凶手1703  阅读(57)  评论(0)    收藏  举报