Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

数据有问题,加了个mod来判断循环,结果WA,直接输出长度就能A

Posted by yobobobo at 2012-08-18 19:42:56 on Problem 2185
#include<stdio.h>
#include<string.h>
#include<cstring>
#define val 10005
int r,c;
char map[val][78];
int next[78*val],cnt[80];
char s[val*78];
void set_next(char *,int );
int main()
{
	int i,j,k,num,index,ans,temp;
	bool flag;
	while(scanf("%d %d",&r,&c)!=EOF)
	{
		memset(cnt,0,sizeof(cnt));
		index=num=0;
		for(i=0;i<r;i++)
			scanf("%s",map[i]);
		cnt[c]=r;
		for(i=0;i<r;i++)
		{
			for(j=1;j<c;j++)
			{
				flag=false;
				temp=c/j;
				for(k=1;k<temp;k++)
				{
					if(strncmp(map[i],map[i]+j*k,j))
					{
						flag=true;
						break;
					}
				}
				temp*=j;
				if(!flag&&c-temp)
					if(strncmp(map[i],map[i]+temp,c-temp))
						flag=true;
				if(!flag)  cnt[j]++;
			}
		}
		for(i=1;i<=c;i++)
			if(cnt[i]==r) break;
		num=i;
		for(i=0;i<r;i++) map[i][num]=0;
		j=0,k=-1;
		next[j]=k;
		while(j<r)
		{
			if(k==-1||strcmp(map[j],map[k])==0)
			{
				j++;
				k++;
				next[j]=k;
			}
			else k=next[k];
		}
		if(r%(r-next[r]))
			ans=(r-next[r])*num;
		else ans=r*num;
		printf("%d\n",ans);
	}
	return 0;
}
void set_next(char *p,int len)
{
	int j,k;
	j=0,k=-1;
	next[j]=k;
	while(j<len)
	{
		if(k==-1||p[j]==p[k])
		{
			j++;
			k++;
			next[j]=k;
		}
		else k=next[k];
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator