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 |
Re:这个稍微改一下就对了~In Reply To:这个稍微改一下就对了~ Posted by:Iamjw at 2010-12-18 03:27:35 可以简化 求横向最小长度时每次比较整列 求纵向最小长度时每次比较整行 #include<stdio.h> #define R 10007 #define C 77 char txt[R][C]; short o[R]; void prp(int (*cmp)(int,int,int),int l,int ll){ int p=0,q=-1; o[p]=q; while(p<l){ while(q>=0&&cmp(p,q,ll))q=o[q]; p++;q++; o[p]=q; } } int cpr(int p,int q,int l){//比较p行与q行 int c; for(c=0;c<l;c++)if(txt[p][c]!=txt[q][c])return 1; return 0; } int cpc(int p,int q,int l){//比较p列与q列 int r; for(r=0;r<l;r++)if(txt[r][p]!=txt[r][q])return 1; return 0; } main(){ int i,r,n,m; while(scanf("%d%d",&n,&m)!=EOF){ for(i=0;i<n;i++)scanf("%s",txt[i]); prp(cpr,n,m); r=n-o[n]; prp(cpc,m,r); r*=m-o[m]; printf("%d\n",r); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator