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

直接暴力竟然只有300ms不到,这题真是太暴力了,付暴力代码

Posted by Belldandy at 2011-05-09 16:22:06 on Problem 2406
#include<stdio.h>
#include<string.h>
char temp[1005000]={0};
int main()
{
	int i=0,N=0,ans=0,j=0;
	while(scanf("%s",&temp))
	{
		N=strlen(temp);
		if(N==1&&temp[0]=='.')
			break;
		for(i=1;i<=N;i++)
		{
			if(N%i==0)
			{
				for(j=i;j<N;j+=i)
				{
					if(strncmp(temp,temp+j,i))
					{
						break;
					}
				}
				if(j==N)
				{
					ans=N/i;
					break;
				}
			}
		}
		printf("%d\n",ans);
	}
}





再次感叹一下库函数的威力

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