• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 24,  comments - 0,  trackbacks - 0
            繼續學習字符串匹配,fighting!!
            題目地址:
            http://poj.org/problem?id=1200

             1 #include<cstdio>
             2 #include<cstring>
             3 #define N 10000000
             4 char str1[N];
             5 char str[N];
             6 bool vis[N];
             7 long long Rabin_Karp(int m,int p,int d)
             8 {
             9     int n=p;
            10     long long t=0;
            11     memset(vis,0,sizeof(vis));
            12     int cnt=0;
            13     long long h=1;
            14     int tm=m-1;
            15     long long tmp=d;
            16     while(tm>0)
            17     {
            18         if(tm&1)
            19             h=h*tmp;
            20         tmp=tmp*tmp;
            21         tm>>=1;
            22     }//printf("h**%lld\n",h);
            23     for(int i=0; i<m; ++i)
            24         t=(d*t+(str[str1[i]]));//printf("%d // ",t);
            25     vis[t]=true;cnt++;//printf("%d ",t[0]);
            26     for(int i=1; i<=n-m; ++i)
            27     {
            28         t=((d*(t-str[str1[i-1]]*h))+(str[str1[i+m-1]]));//printf("%d // ",t);
            29         if(!vis[t])
            30         {vis[t]=true;cnt++;}
            31     }//printf("**%d\n",cnt );
            32     return cnt;
            33 }
            34 int main()
            35 {
            36     int n,nc;
            37    // while(scanf("%d%d",&n,&nc)!=EOF)
            38    // {
            39         scanf("%d%d",&n,&nc);
            40         scanf("%s",str1);
            41         int len=strlen(str1);
            42         memset(str,0,sizeof(str));
            43         int count=1;
            44         for(int i=0;i<len;++i)if(!str[str1[i]])str[str1[i]]=count++;
            45         long long ans=Rabin_Karp(n,len,nc);
            46         printf("%lld\n",ans);
            47   //  }
            48     return 0;
            49 }

            posted on 2011-08-26 15:59 ACSeed 閱讀(179) 評論(0)  編輯 收藏 引用
            99久久99这里只有免费费精品| 99久久99这里只有免费费精品| 精品久久久久久久久久中文字幕 | 久久国产精品无码HDAV| 香蕉久久影院| 亚洲欧洲中文日韩久久AV乱码| 久久久久亚洲精品男人的天堂| 欧美与黑人午夜性猛交久久久 | 94久久国产乱子伦精品免费 | 久久亚洲国产欧洲精品一| 东京热TOKYO综合久久精品| 免费观看久久精彩视频| 精品国产日韩久久亚洲| 久久免费视频观看| 2021国产精品午夜久久| 91精品国产综合久久香蕉| 77777亚洲午夜久久多人| 久久综合亚洲色HEZYO国产| 麻豆一区二区99久久久久| 性欧美大战久久久久久久| 国产精品美女久久福利网站| 精品国产福利久久久| 久久超碰97人人做人人爱| 国产成人综合久久精品红| 久久亚洲精品成人无码网站| 欧洲性大片xxxxx久久久| 久久久精品久久久久久| 精品久久久久久无码人妻蜜桃| 久久亚洲国产中v天仙www| 国产69精品久久久久9999| 久久国产免费| 中文字幕久久精品无码| 久久久91精品国产一区二区三区| 国产午夜福利精品久久2021| 久久天天躁狠狠躁夜夜躁2O2O| 国产成人精品白浆久久69| 久久se精品一区二区影院| 99久久无色码中文字幕| 久久综合日本熟妇| 岛国搬运www久久| 品成人欧美大片久久国产欧美|