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

hash素数要怎么取才好呢 各位大牛 小弟WA了

Posted by ACM_henry at 2008-10-12 20:36:04 on Problem 1200
#include <iostream>
using namespace std;
char p[20000000];
bool hash[10000001];
int prim=10000001;
bool find(int sum)
{
	if(hash[sum%prim]==1)
	{
		return 0;
	}
	else hash[sum%prim]=1;
	return 1;
}
int main()
{
	int ans=0;
	memset(hash,0,sizeof(hash));
	int n,c;
	cin>>n>>c;
	getchar();
	int i;
	gets(p);
	int num=strlen(p);
	int j;
	int sum;
	for(i=0;i<=num-n;i++)
	{
		sum=0;
		for(j=i;j<i+n;j++)
		{
			sum*=26;
			sum+=p[j]-'a';
		}
		if(find(sum))
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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