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 |
为什这个离散数组 cn[1000000];要开到1000000才能过。。。不是128就好了吗。。。#include<cstdio> #include<cstring> using namespace std; bool hash[8000000]; int cn[1000000]; char s[16000000]; int main() { int n,nc,pos=1,ans=0; char ch; scanf("%d%d",&n,&nc); int i=0; scanf("%s",s); int len=strlen(s); for(i=0;i<len;i++) { if(cn[s[i]]==0) cn[s[i]]=pos++; } for(i=0;i<len;i++) { int sum=0,j; for( j=i;j<len&&j<i+n;j++) { sum=nc*sum+cn[s[j]]; } if(j-i==n&&hash[sum]==0) { ans++; hash[sum]=1; } } printf("%d\n",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator