POJ-3461 Oulipo(KMP)
来源:互联网 发布:qq for linux ubuntu 编辑:程序博客网 时间:2024/06/05 18:08
题目链接:http://poj.org/problem?id=3461
题目大意:
给你两个字符串p和s,求出p在s中出现的次数。
思路:p在s中KMP匹配,匹配成功,再从next[last]的位置匹配即可,因为允许出现的两次有重叠的部分。
//1208 KB94 ms#include<cstdio>#include<iostream>#include<cstring>using namespace std;int n;char s[1000100],p[10100];int next[10100];void getnext(){ next[0]=-1; int i=0,j=-1; while(p[i]!=0){ while(j>-1&&p[i]!=p[j]) j=next[j]; j++; i++; next[i]=j; }}int KMP(){ int i=0,j=0,ans=0; while(s[i]!=0){ if(j==-1||s[i]==p[j]){ j++; i++; if(p[j]==0){ ans++; j=next[j]; } } else j=next[j]; } return ans;}int main(){ int _; scanf("%d",&_); while(_--){ scanf("%s%s",p,s); getnext(); printf("%d\n",KMP()); } return 0;}
0 0
- POJ 3461 - Oulipo(KMP)
- POJ-3461 Oulipo(KMP)
- Poj 3461 Oulipo (KMP)
- POJ---3461-Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- 【POJ 3461】Oulipo(kmp)
- poj 3461 Oulipo(KMP)
- poj 3461 Oulipo(KMP)
- poj 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo---kmp
- POJ 3461 Oulipo KMP
- poj 3461 Oulipo (KMP)
- POJ 3461 Oulipo ( KMP )
- POJ 3461 Oulipo KMP
- POJ 3461 Oulipo / KMP
- Oulipo - POJ 3461 KMP
- 安装hbase集群
- UVA 116 Unidirectional TSP
- op 正向端pin,电阻的作用
- 怎样在Tomcat中配置外部Web应用程序路径
- 【瞎搞】 HDU 1029 Ignatius and the Princess IV
- POJ-3461 Oulipo(KMP)
- Hibernate抓取策略
- UVA 348 Optimal Array Multiplication Sequence
- HTML页面中的的美化checkbox
- 《Python核心编程》第四章练习解析
- 《手游开发笔记-1》
- 郑风田:老美哪些地儿值得咱们?
- poj1064 Cable master
- Pattern Evaluation