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素数要怎么取才好呢 各位大牛 小弟WA了#include <iostream> using namespace std; char p[20000000]; bool hash[10000001]; int prim=10000001; bool find(int sum) { if(hash[sum%prim]==1) { return 0; } else hash[sum%prim]=1; return 1; } int main() { int ans=0; memset(hash,0,sizeof(hash)); int n,c; cin>>n>>c; getchar(); int i; gets(p); int num=strlen(p); int j; int sum; for(i=0;i<=num-n;i++) { sum=0; for(j=i;j<i+n;j++) { sum*=26; sum+=p[j]-'a'; } if(find(sum)) { ans++; } } cout<<ans<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator