Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
过了的能讲讲怎么做HASH?还没有尝过HASH的味道......我的代码..大家看看什么不是HASH...#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator