hdu1686 KMP裸题
来源:互联网 发布:node.js python 编辑:程序博客网 时间:2024/05/21 08:03
秋招快有着落啦,十一月中去北京区赛膜拜众神。
哎,好长一段时间没有刷过,重头拾起,最近得专题是字符串。
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 <iostream>#include <cstdio>#include <string>#include <cstring>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<<q<<endl; } } return res;}int main(){ int C; p[0]=T[0]='1'; while(scanf("%d",&C)!=EOF){ while(C--){ scanf("%s",p+1); scanf("%s",T+1); printf("%d\n",kmp(strlen(T)-1,strlen(p)-1)); } }}
1 0
- hdu1686 KMP裸题
- hdu1686 KMP算法
- hdu1686之KMP
- hdu1686 Oulipo(KMP)
- hdu1686 KMP水题
- hdu1686 oulipo 【KMP】
- HDU1686 Oulipo(扩展KMP)
- hdu1686 Oulipo (KMP)
- hdu1686 Oulipo--KMP
- hdu1686 Oulipo kmp
- HDU1686(KMP)
- hdu1686 Oulipo【kmp】
- HDU1686(KMP多次匹配)
- HDU1686 kmp算法
- hdu1686 KMP算法
- HDU1686:Oulipo KMP算法
- hdu1686--kmp入门题
- 初步理解KMP--HDU1686
- win7下配置FTP服务
- lightoj 1369 Answering Queries
- 哈夫曼树及哈夫曼编码
- 黑马程序员-java基础篇
- dubbo注册zookepper神奇IP
- hdu1686 KMP裸题
- Matlab数据类型的转换
- git tag
- 新人写博文总结今天所学 JSP里javaBean定义和getProperty、setProperty
- HDU-4961 Boring Sum STL模拟
- C++ primer 第五版 中文版 练习 12.2 个人code
- Jsoup解析html
- hdu 1022 Train Problem I
- pictureBox sizemode=zoom时图片像素坐标