HDU 1711 Number Sequence KMP
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1711
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef long long LL;
const int N=10005;
const LL II=100000000;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); int next[N],tlen,wlen;
int text[1000009],word[N]; void getnext(int *p)
{
int j=0,k=-1;
next[0]=-1;
while(j<wlen)//len是p的长度
{
if(k==-1||p[j]==p[k])
{
j++; k++;
next[j]=k;
}
else
k=next[k];
}
} int kmp(int *text,int *word)//主串、模式串
{//返回从第几个开始出现模式串
int i=0,j=0,k=0;
while(i<tlen)
{
if(j==-1||text[i]==word[j])
{
i++;j++;
}
else
j=next[j];
if(j==wlen) return i-wlen+1;
}
return -1;
} int main()
{
int i,j,T;
cin>>T;
while(T--)
{
scanf("%d%d",&tlen,&wlen);
for(i=0;i<tlen;i++)
scanf("%d",&text[i]);
for(i=0;i<wlen;i++)
scanf("%d",&word[i]);
getnext(word);
int xx=kmp(text,word);
printf("%d\n",xx);
}
return 0;
}
HDU 1711 Number Sequence KMP的更多相关文章
- HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1711 Number Sequence KMP 基础题
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 1711 Number Sequence (KMP 入门)
Number Sequence Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and ...
- HDU 1711 - Number Sequence - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- HDU 1711 Number Sequence (字符串匹配,KMP算法)
HDU 1711 Number Sequence (字符串匹配,KMP算法) Description Given two sequences of numbers : a1, a2, ...... , ...
- HDU 1711 Number Sequence(数列)
HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 1711 Number Sequence 【KMP应用 求成功匹配子串的最小下标】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/O ...
- HDU 1711 Number Sequence(KMP)附带KMP的详解
题目代号:HDU 1711 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/ ...
- HDU 1711 Number Sequence (KMP简单题)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- MySQL5.7.11(ZIP)安装
1.环境变量-系统变量: Path添加:;D:\worksoftware\mysql-5.7.11\bin 2.配置更改:my-default.ini,注意是ANSI编码 添加 #(mysql所在目录 ...
- Redhat Linux内核升级全记录(转)
http://www.sina.com.cn 2001/06/15 15:38 中国电脑教育报 李红 Redhat Linux因为比较容易上手,所以用户很多.它系统配置完善,预装了丰富的应 ...
- Umbraco隐藏属性
Umbraco默认的Url地址,是根据Node路径来默认显示的,因此使用中文的话比较尴尬. 网上有传的方法,是修改源码,来实现Url的重写. 但实际大可不必如此麻烦,只需要增加两个类型为Textstr ...
- android小知识之多个listview在同一界面只有item高亮
我的工程里面一个activity有两个有圆角的listview,就是 自定义的 CornerListView继承ListView, 然后 我想圆角的listview A点击之后一个item会高亮 ...
- 部署nginx+rsyslog补丁
nginx 配置: user nginx; worker_processes 1; syslog local5 nginx; error_log /var/log/nginx/nginx_error. ...
- tomcat 7 无法打开管理页面
在配置文件tomcat-users.xml中添加如下内容即可. <role rolename="admin"/> <role rolename="man ...
- Migration data on SQL
从表里面导出数据XML: -- export declare @xml xml set @xml = (select * from ( select TableName = 'Schema', xml ...
- Unity Editor下对资源进行操作时调用AssetModificationProcessor
public class Test : UnityEditor.AssetModificationProcessor { private static void OnWillCreateAsset(s ...
- The Painter's Partition Problem Part II
(http://leetcode.com/2011/04/the-painters-partition-problem-part-ii.html) This is Part II of the art ...
- POJ 3376 Finding Palindromes(扩展kmp+trie)
题目链接:http://poj.org/problem?id=3376 题意:给你n个字符串m1.m2.m3...mn 求S = mimj(1=<i,j<=n)是回文串的数量 思路:我们考 ...