博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1711 Number Sequence KMP 基础题
阅读量:6343 次
发布时间:2019-06-22

本文共 1767 字,大约阅读时间需要 5 分钟。

Number Sequence

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11691    Accepted Submission(s): 5336
Problem Description
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1], a[K + 1] = b[2], ...... , a[K + M - 1] = b[M]. If there are more than one K exist, output the smallest one.
 
Input
The first line of input is a number T which indicate the number of cases. Each case contains three lines. The first line is two numbers N and M (1 <= M <= 10000, 1 <= N <= 1000000). The second line contains N integers which indicate a[1], a[2], ...... , a[N]. The third line contains M integers which indicate b[1], b[2], ...... , b[M]. All integers are in the range of [-1000000, 1000000].
 
Output
For each test case, you should output one line which only contain K described above. If no such K exists, output -1 instead.
 
Sample Input
 
2 13 5 1 2 1 2 3 1 2 3 1 3 2 1 2 1 2 3 1 3 13 5 1 2 1 2 3 1 2 3 1 3 2 1 2 1 2 3 2 1
 
Sample Output
 
6 -1
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:            
题意:给两个数组a和b,求b在a中出现的的第一个位置,若没有则输出-1,仅仅是数组变成了整型数组,方法与字符数组全然一样。
代码:
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1000005#define MAXN 2005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;int s[maxn],p[maxn],nextval[maxn];int N,M;void get_nextval(){ int i=0,j=-1; nextval[0]=-1; while (i

转载地址:http://fhkla.baihongyu.com/

你可能感兴趣的文章
Asp.Net文件下载
查看>>
BZOJ3312:[USACO]No Change(状压DP)
查看>>
事件处理基础知识(一)捕获、目标、冒泡三个阶段
查看>>
灵异小说推荐
查看>>
Problem 1061 - ACM码
查看>>
centos6.9下设置nginx服务开机自动启动
查看>>
Apache:如何利用.htaccess文件对PHP网站或文件进行伪静态处理
查看>>
hibernate(三)基本配置,log4j、JUnit配置
查看>>
中小河流雨水情监测_水文监测预警系统
查看>>
Chapter 6. 文件上传
查看>>
vue-cli3 chainWebpack配置,去除打包后文件的预加载prefetch/preload(已解决)
查看>>
20165231 预备作业二:学习基础和C语言基础调查
查看>>
获取tranform参数函数的封装
查看>>
Linux 文件系统 相关
查看>>
java基础值向上向下转型
查看>>
模态框
查看>>
电影评论分类--二分类问题
查看>>
两位顶级社会工程学大师:凯文-米特尼克和 弗兰克-阿巴内尔
查看>>
JavaScript中的Function类型总结
查看>>
添加gif效果图
查看>>