KMP模板题 Number Sequence HDU1711
模板...嗯
#include <iostream>
#include <cstdio>
#include <string.h>
#pragma warning ( disable : 4996 )
using namespace std; const int inf = 0x3f3f3f3f;
const int maxn = 1e4+;
const int vspot = 1e6+; int net[maxn];
int num[maxn], test[vspot];
int N, M, ans; void getnext()
{
memset( net, , sizeof(net) );
ans = ;
int len = M; int k = -, j = ;
net[j] = -; while ( j < len- )
{
if ( k==- || num[j]==num[k] )
{
k++;
j++;
net[j] = k;
}
else
k = net[k];
}
} void solve()
{
int i = , j = ;
while ( i < N && j < M )
{
if( j == - || test[i] == num[j] )
{ i++; j++; }
else
j = net[j];
}
if( j == M )
ans = i-j+;
else
ans = -;
} int main()
{
int all;
cin >> all;
while (all--)
{
cin >> N >> M;
for( int i = ; i < N; i++ )
scanf( "%d", &test[i] );
for( int i = ; i < M; i++ )
scanf( "%d", &num[i] ); getnext();
solve();
printf( "%d\n", ans );
}
return ;
}
KMP模板题 Number Sequence HDU1711的更多相关文章
- (KMP 模板)Number Sequence -- Hdu -- 1711
http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/Other ...
- HDU 1711 - Number Sequence - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- POJ Oulipo KMP 模板题
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4 ...
- POJ Oulipo(KMP模板题)
题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...
- HDU1711 Number Sequence(KMP模板题)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Number Sequence - HDU 1711(KMP模板题)
题意:给你一个a串和一个b串,问b串是否是a串的子串,如果是返回b在a中最早出现的位置,否则输出-1 分析:应该是最简单的模板题了吧..... 代码如下: ==================== ...
- hdu 1711 Number Sequence(KMP模板题)
我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...
- HDU 1711Number Sequence【KMP模板题】
<题目链接> 题目大意: 意思是给出两个串,找出匹配串在模式串中的位置. 解题分析: KMP算法模板题. #include <cstdio> #include <cstr ...
- POJ:3461-Oulipo(KMP模板题)
原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...
随机推荐
- MongoDB特性及使用场景
概述 MongoDB(Humongous Database),中文意思就是巨大无比的数据库,顾名思义,MongoDB就是为处理大数据而生,以解决海量数据的存储和高效查询使用为使命.MongoDB是一款 ...
- MyBatis - Generator(MBG)
前言 MyBatis Generator简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器, 可以快速的根据数据表自动生成Bean对象.Java接口及SqlMapper.xml配置文件. ...
- Office2016只安装三件套方法
转载 Office2016只安装三件套方法(word,ppt,excel) 2019-03-01 23:30:03 Kellen5l 阅读数 11618更多 分类专栏: Office 版权声明:本 ...
- js 删除数组中指定值
var arr = ['1','2'];delete('1'); function delete(i){ var index = arr.indexOf(i); arr.splice(index, 1 ...
- Java开发系列-文件上传
概述 Java开发中文件上传的方式有很多,常见的有servlet3.0.common-fileUpload.框架.不管哪种方式,对于文件上传的本质是不变的. 文件上传的准备 文件上传需要客户端跟服务都 ...
- 2、docker镜像管理
Docker镜像管理 镜像是Docker容器的基础,想运行一个Docker容器就需要有镜像.我们上面已经学会了使用search搜索镜像.那么这个镜像是怎么创建的呢? 创建镜像 镜像的创建有以下几种方法 ...
- 如果try中有return那么finally中不要有return不然不会执行try中的return
public class TryExer { public static void main(String[] args) { String test = test(); System.out.pri ...
- Android开发 Html工具类详解
前言 在一些需求富文本显示或者编辑的开发情况下,数据都是用html的格式来保存文本信息的.而google是有提供解析html的工具类那就是Html.有了Html可以让TextView也支持富文本(其实 ...
- Android开发 EditText的开发记录
设置显示内容与隐藏内容 if (isChecked){ editPassword.setTransformationMethod(HideReturnsTransformationMethod.get ...
- JZOJ[3771] 【NOI2015模拟8.15】小 Z 的烦恼
题目 描述 题目大意 有从111到nnn的数字,每个数字都可以放在一个盒子里(可以不放).一旦放,满足: 如果它不在第mmm个盒子,那么它的两倍一定在后面一个盒子里. 如果它不在第111个盒子,那么它 ...