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

最后还是靠统计字符的出现次序过的。。。为什么原生态统计ASCII码值对应hash不行呢?哪位路过的大牛给解释一下吧~

Posted by Zeor at 2009-05-20 10:29:02 on Problem 1200
#include <stdio.h>
#include <string.h>
#define MAX 40000000
bool hash[MAX]={0};
char str[MAX];
int main()
{
	int n,nc,len,count=0,flag=0;
	scanf ("%d %d",&n,&nc);
	scanf ("%s",str);
	len=strlen(str);
	for (int i=0;i<len;i++)
	{
		int sum=0;
		flag=0;
		for (int j=i;j<i+n&&j+n<len;j++)
		{
			flag=1;
		//	printf ("%c",str[j]);
			sum=sum*nc+str[j];
		}
		//printf ("\n");
		if(!hash[sum]&&flag)
		{
			hash[sum]=1;
			count++;
		}
	}
	printf ("%d\n",count);
	//while(1);
}


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