| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求最小公倍数考虑得太复杂了。。。矩阵行列互不影响诶 可以先把每行看成一个元素求循环节,再把每列看成一个元素求循环节。。。然后相乘即可。 附简单易懂暴力代码(慢,因为string很慢) #include<cstdio> #include<cstring> #include<cstdlib> #include<string> #include<iostream> using namespace std; int r,c,rl=1,cl=1; string g[11000],g2[11000]; int mcs[11000]; int main() { scanf("%d%d",&r,&c); for(int i=1;i<=r;i++) cin>>g[i]; int t=1,tmcs=-1;mcs[0]=-1; for(int i=1;i<=r;i++) { while(tmcs!=-1) { if(g[i].compare(g[tmcs+1])==0) { tmcs++;mcs[i]=tmcs;break; } else tmcs=mcs[tmcs]; } if(tmcs==-1) { mcs[i]=0;tmcs=0; } } for(int i=1;i<=r;i++) { if(g[i].compare(g[t])==0) { t=t%rl+1; } else { rl=i-mcs[i]; t=mcs[i]%rl+1; } } for(int i=1;i<=r;i++) for(int j=0;j<c;j++) g2[j+1]+=g[i][j]; memset(mcs,0,sizeof(mcs)); t=1,tmcs=-1;mcs[0]=-1; for(int i=1;i<=c;i++) { while(tmcs!=-1) { if(g2[i].compare(g2[tmcs+1])==0) { tmcs++;mcs[i]=tmcs;break; } else tmcs=mcs[tmcs]; } if(tmcs==-1) { mcs[i]=0;tmcs=0; } } for(int i=1;i<=c;i++) { if(g2[i].compare(g2[t])==0) { t=t%cl+1; } else { cl=i-mcs[i]; t=mcs[i]%cl+1; } } printf("%d",rl*cl); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator