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?还没有尝过HASH的味道......我的代码..大家看看什么不是HASH...

Posted by 003 at 2005-09-19 20:55:35 on Problem 1200
#include<stdio.h>
#include<string.h>

#define size 160

char* hash[size+1];
char s[size+10];
int N,NC;

bool hashfind(int k)
{
	int t=1,index = ((s[k]+19)*(s[k]+131)*((s[k+N-1]+3331)>>1)*31)%size;
	if(index<0) index = (index+214748367)%size;
	while(hash[index] && (t=strncmp(hash[index],s+k,N))!=0) index++;
	if(t) { hash[index] = s+k; return true; }
	return false;
}

int solve()
{
	int i,res=0;
	int len = strlen(s);
	len = len-N+1;
	for(i=0;i<len;i++)
		if(hashfind(i)) res++;
	return res;
}

int main()
{
	if(!freopen("1200.in","r",stdin)) return 1; 
	scanf("%d%d",&N,&NC);
	scanf("%s",s);
	printf("%d\n",solve());
	return 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