模板...嗯

 #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的更多相关文章

  1. (KMP 模板)Number Sequence -- Hdu -- 1711

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/Other ...

  2. HDU 1711 - Number Sequence - [KMP模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  3. POJ Oulipo KMP 模板题

    http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4 ...

  4. POJ Oulipo(KMP模板题)

    题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...

  5. HDU1711 Number Sequence(KMP模板题)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. Number Sequence - HDU 1711(KMP模板题)

    题意:给你一个a串和一个b串,问b串是否是a串的子串,如果是返回b在a中最早出现的位置,否则输出-1   分析:应该是最简单的模板题了吧..... 代码如下: ==================== ...

  7. hdu 1711 Number Sequence(KMP模板题)

    我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...

  8. HDU 1711Number Sequence【KMP模板题】

    <题目链接> 题目大意: 意思是给出两个串,找出匹配串在模式串中的位置. 解题分析: KMP算法模板题. #include <cstdio> #include <cstr ...

  9. POJ:3461-Oulipo(KMP模板题)

    原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...

随机推荐

  1. 16.ajax_case07

    # 通过搜索接口抓取etherscan上的合约地址 # https://etherscan.io/ import requests import re header = { 'Accept': 'te ...

  2. awk 一些题目

    1.1. 输出记录最多的IP [腾讯面试题]:一个文本类型的文件,里面每行存放一个登陆者的IP(某些行是重复的),写一个shell脚本输出登陆次数最多的用户. Ip_input.txt的内容假设如下: ...

  3. 在Eclipse中修改Jsp页面的新增模板

    打开Eclipse的Preferences页面 路径: Window à Preferences 搜索"jsp",点击"Templates",选择要修改的Jsp ...

  4. visual studio 2017--括号自动补全

    ---恢复内容开始--- 平常在visual studio中编写C++代码,一般括号之类的都是自动补全的,最近想用来编写Python,发现括号不能补全了,很不适应. Python编写时好像括号好像默认 ...

  5. 建立 CRAMFS 包

    下载 cramfs 工具 从 http://prdownloads.sourceforge.net/cramfs/cramfs­1.1.tar.gz下载源代码包. 把下载包拷贝到 dev_home/t ...

  6. C++右值引用与转移语义

    std::forwad? C++11 中定义的 T&& 的推导规则为: 右值实参为右值引用,左值实参仍然为左值引用. 参考: 右值引用与转移语义

  7. Stopwatch 计时器类

    C#_Stopwatch 类   命名空间:System.Diagnostics Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间.在典型的 Stopwatc ...

  8. 使用Cookie实现显示用户上次访问时间

    一. 常用Cookie API介绍 1. 获取cookie request.getCookies();  // 返回Cookie[] 2. 创建cookie Cookie(String key, St ...

  9. webpack 配置分离css插件

    以css配置示例,less与sass同理 1. 使用旧版的ExtractTextPlugin插件 安装 npm install extract-text-webpack-plugin@next --s ...

  10. CobaltStrike与Metasploit实战联动

    前言 CobalStrike 与 Metasploit 均是渗透利器,各有所长.前者更适合做稳控平台,后者则更擅长内网各类探测搜集与漏洞利用.两者更需要灵活的联动,各自相互依托,从而提升渗透的效率. ...