POJ – 1200 Crazy Search

http://poj.org/problem?id=1200


#include<iostream> #include<cstring> using namespace std; const int maxn=2e7; int len,base,myhash[300],ans=0; bool vis[17001005]; char s[maxn]; int main(){ memset(vis,0,sizeof(bool)*16000005); scanf("%d%d%s",&len,&base,s); int base1=base; //把字符串转换为base进制的数 int I=strlen(s); for(int i=0;i<I;i++) if(!myhash[s[i]]) myhash[s[i]]=base1--;    //所有出现的字符映射成数 for(int i=0;i<=I-len;i++){ int sum=0; for(int j=0;j<len;j++) sum=(sum*base+myhash[s[i+j]]); if(!vis[sum]){ vis[sum]=1; ans++; } } cout<<ans<<endl; return 0;}
原文地址:https://www.cnblogs.com/spzeno/p/10527775.html