标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 27336 | Accepted: 7641 |
Description
Input
Output
Sample Input
3 4 daababac
Sample Output
5
Hint
Source
好吧好吧,我这次就直接上别人的程序了(*^__^*)
1 #include<stdio.h> 2 #include<string.h> 3 #define mem(a) memset(a,0,sizeof(a)) 4 5 unsigned int hash[16000000+5]; 6 unsigned int c[128]; 7 char str[1000000]; 8 9 int main() 10 { 11 int len,base; 12 while(~scanf("%d%d",&len,&base)) 13 { 14 mem(str); 15 mem(c); 16 mem(hash); 17 scanf("%s",str); 18 int num =0; 19 int i,j=0,length=strlen(str),tp=1; 20 for(i=0;i<length;i++) 21 { 22 if(c[str[i]]==0)c[str[i]]=++j; 23 if(j==base)break; 24 } 25 for(i=0;i<len;i++) 26 { 27 num=num*base+c[str[i]]-1; 28 tp*=base; 29 } 30 tp/=base; 31 hash[num]=1; 32 int count=1; 33 for(i=1;i<=length-len;i++) 34 { 35 num = ( num-(c[str[i-1]]-1)*tp )* base+ c[str[i+len-1]] - 1; 36 if(!hash[num]) 37 { 38 hash[num]=1; 39 count++; 40 } 41 } 42 printf("%d\n",count); 43 } 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/Michaelzzn/p/5766773.html