hdu 1711Number Sequence(kmp模板题)

Number Sequence

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19127    Accepted Submission(s): 8218


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

题意:给你n,m(1 <= M <= 10000, 1 <= N <= 1000000),接下来分别是长度为nm的两个数组,求第二个数组在第一个数组中最先被完全匹配的位置。

 

思路:kmp模板题.当第二个数组匹配到位置m,只要输出此时第一个数组此时的位置-m+1便可以了.


#include<bits/stdc++.h>
using namespace std;
const int maxn=1100000;
int n,m;
int pattern[maxn],s[maxn];
int Next[maxn];

void get_next(){
    int i=0,j=-1;
    Next[0]=-1;
    while(i<m){
        if(j==-1||pattern[j]==pattern[i]){
            j++,i++;
            Next[i]=j;
        }
        else
            j=Next[j];
    }
}

void Kmp(){
    int i=0,j=0,flag=0;
    while(i<n){
        if(j==-1||s[i]==pattern[j])
            i++,j++;
        else
            j=Next[j];
        if(j==m){
            printf("%d\n",i+1-m);
            flag=1;
            break;
        }
    }
    if(flag==0)
        printf("-1\n");
}

int main(){
    int _;
    scanf("%d",&_);
    while(_--){
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
            scanf("%d",&s[i]);
        for(int i=0;i<m;i++)
            scanf("%d",&pattern[i]);
        get_next();
        Kmp();
    }
    return 0;
}


内容概要:本文档详细介绍了利用Google Earth Engine (GEE) 平台对指定区域(位于中国广东省某地)进行遥感影像处理的一系列操作。首先,定义了研究区边界,并选取了 Landsat 8 卫星2023年8月至10月期间的数据,通过去云处理、归一化等预处理步骤确保数据质量。接着,基于预处理后的影像计算了地表温度(LST)、归一化植被指数(NDVI)、湿度指数(WET)、建筑指数(NDBSI)四个关键指标,并进行了主成分分析(PCA),提取出最重要的信息成分。为了进一步优化结果,还应用了像素二元模型对主成分分析的第一主成分进行了条件规范化处理,生成了最终的环境状态评估指数(RSEI)。最后,利用JRC全球表面水体数据集对水体区域进行了掩膜处理,保证了非水体区域的有效性。所有处理均在GEE平台上完成,并提供了可视化展示及结果导出功能。 适合人群:具备地理信息系统基础知识,对遥感影像处理有一定了解的研究人员或技术人员。 使用场景及目标:① 对特定区域的生态环境状况进行定量评估;② 为城市规划、环境保护等领域提供科学依据;③ 掌握GEE平台下遥感影像处理流程和技术方法。 其他说明:本案例不仅展示了如何使用GEE平台进行遥感影像处理,还涵盖了多种常用遥感指标的计算方法,如LST、NDVI等,对于从事相关领域的科研工作者具有较高的参考价值。此外,文中涉及的代码可以直接在GEE代码编辑器中运行,便于读者实践操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值