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

为什这个离散数组 cn[1000000];要开到1000000才能过。。。不是128就好了吗。。。

Posted by 201030720425 at 2011-07-30 11:59:14 on Problem 1200
#include<cstdio>
#include<cstring>
using namespace std;
bool hash[8000000];
int cn[1000000];
char s[16000000];
int main()
{
	int n,nc,pos=1,ans=0;
	char ch;
	scanf("%d%d",&n,&nc);
	int i=0;
	scanf("%s",s);
	int len=strlen(s);
	for(i=0;i<len;i++)
	{
		if(cn[s[i]]==0)
			cn[s[i]]=pos++;
	}
	for(i=0;i<len;i++)
	{
		int sum=0,j;
		for( j=i;j<len&&j<i+n;j++)
		{
			sum=nc*sum+cn[s[j]];
		}
		if(j-i==n&&hash[sum]==0)
		{
			ans++;
			hash[sum]=1;
		}
	}
	printf("%d\n",ans);
	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