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 |
怎么这样写还超时呢 求救!!!!!#include <iostream> using namespace std; char p[16000010]; const int prim=111111111; int hash[prim]; int find(int v) { int a = v / 32; int b = v % 32; return (hash[a]&(1<<b)); } void insert(int v) { int a = v / 32; int b = v % 32; hash[a] |= 1 << b; } int main() { int length,num; cin>>length>>num; scanf("%s",p); int sum; int i; int j; int ans=0; for(i=0;i<=strlen(p)-length;i++) { sum=0; for(j=i;j<i+length;j++) { sum+=num*sum+p[j]-'a'; } if(find(sum)==0) { ans++; } insert(sum); } 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