设为首页 加入收藏

TOP

hdu1686 KMP裸题
2015-07-20 17:37:05 来源: 作者: 【 】 浏览:2
Tags:hdu1686 KMP 裸题

秋招快有着落啦,十一月中去北京区赛膜拜众神。

哎,好长一段时间没有刷过,重头拾起,最近得专题是字符串。

Trie前一排又敲了一遍,KMP今天敲了一下。

题目一大堆废话,实际就是判断模式串出现得次数,我是对着算法导论伪代码敲得,一次AC,真得很水。

/***********************************************************
	> OS     : Linux 3.13.0-24-generic (Mint-17)
	> Author : yaolong
	> Mail   : dengyaolong@yeah.net
	> Time   : 2014年09月24日 星期三 15时31分51秒
 **********************************************************/
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; int next[12345]; char p[12345]; char T[1234567]; void build_next ( int m ) { next[1] = 0; int k = 0; for ( int q = 2; q <= m; q++ ) { while ( k > 0 && p[k + 1] != p[q] ) { k = next[k]; } if ( p[k + 1] == p[q] ) { k = k + 1; } next[q] = k; } } int kmp ( int n, int m ) { build_next ( m ); int q = 0; int res = 0; for ( int i = 1; i <= n; i++ ) { while ( q > 0 && p[q + 1] != T[i] ) { q = next[q]; } if ( p[q + 1] == T[i] ) { q = q + 1; } if ( q == m ) { //cout << "Here" << i-m<<"q"; ++res; q = next[q]; //cout<
      
       

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Ant如何打包UIAutomator项目用到.. 下一篇HDU-4961 Boring Sum STL模拟

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·用 Python 进行数据 (2025-12-25 15:49:09)
·如何学习Python数据 (2025-12-25 15:49:07)
·利用Python进行数据 (2025-12-25 15:49:04)
·Java 学习线路图是怎 (2025-12-25 15:19:15)
·关于 Java 学习,有 (2025-12-25 15:19:12)