ac自动机简介及补题二

自动机我们已经介绍过了(可以看http://blog.youkuaiyun.com/invariance/article/details/78066932),所谓ac自动机就是识别串T是否能被自动机内的trie以某种方式匹配的自动机,trie可以表示多个单词。那么我们需要做的就是找到一种合适的方法缩短判断串T是否以某种方式被匹配的时间。

解法:一般的字符串算法本质上是一种奥卡姆剃刀式的算法,充分利用已有信息去减少重复的工作(空间换时间)。ac自动机也是如此,比如说在一个串上匹配到不匹配字符时,之前的子串我们已知,那么我们可以像kmp一样做一个等价转移。像kmp的next的一样,ac自动机可以建构一个fail(下面代码是用next表示子父关系的)。fail【now】表示和root到now后缀串同样的字符节点,同时是小于等于now的深度的最深的节点。所以我们可以用队列(bfs)递推的求fail,求出fail后用法和kmp的next的基本一致。 

入门版题(hdu2222):

题面:

In the modern time, Search engine came into the life of everybody like Google, Baidu, etc.
Wiskey also wants to bring this feature to his image retrieval system.
Every image have a long description, when users type some keywords to find the image, the system will match the keywords with description of image and show the image which the most keywords be matched.
To simplify the problem, giving you a description of image, and some keywords, you should tell me how many keywords will be match.

解法:板题end【可以表示在该节点处结束的单词串的个数】。ans累加end。

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
struct trie{
    int next[500010][26],fail[500010],end[500010];
    int root,l;
    int newnode(){
        for(int i=0;i<26;i++)
        next[l][i]=-1;
        end[l++]=0;
        return l-1;
    }
    void init(){
        l=0;
        root=newnode();
    }
    void insert(char b[]){
        int len=strlen(b);
        int now=root;
        for(int i=0;i<len;i++){
            if(next[now][b[i]-'a']==-1)
            next[now][b[i]-'a']=newnode();
            now=next[now][b[i]-'a'];
        }
        end[now]++;
    }
    void build(){
        queue<int>p;
        fail[root]=root;
        for(int i=0;i<26;i++)
            if(next[root][i]==-1)
                next[root][i]=root;
            else {
                fail[next[root][i]]=root;
                p.push(next[root][i]);
            }
        while(!p.empty()){
            int now=p.front();
            p.pop();
            for(int i=0;i<26;i++)
                if(next[now][i]==-1)
                    next[now][i]=next[fail[now]][i];
                else{
                    fail[next[now][i]]=next[fail[now]][i];
                    p.push(next[now][i]);
                }
            
        }
    }
    int query(char b[]){
        int len=strlen(b);
        int now=root;
        int ans=0;
        for(int i=0;i<len;i++){
            now=next[now][b[i]-'a'];
            int cha=now;
            while(cha!=root){
                ans+=end[cha];
                end[cha]=0;
                cha=fail[cha];
            }
        }
        return ans;
    }
};
char b[1000010];
trie ac;
int main(){
    int t,n;
    scanf("%d",&t);
    while (t--) {
        scanf("%d",&n);
        ac.init();
        for(int i=0;i<n;i++){
            scanf("%s",b);
            ac.insert(b);
        }
        ac.build();
        scanf("%s",b);
        printf("%d\n",ac.query(b));
    }
    return 0;
}

本研究利用Sen+MK方法分析了特定区域内的ET(蒸散发)趋势,重点评估了使用遥感数据的ET空间变化。该方法结合了Sen斜率估算器和Mann-Kendall(MK)检验,为评估长期趋势提供了稳健的框架,同时考虑了时间变化和统计显著性。 主要过程与结果: 1.ET趋势可视化:研究利用ET数据,通过ET-MK和ET趋势图展示了蒸散发在不同区域的空间和时间变化。这些图通过颜色渐变表示不同的ET水平及其趋势。 2.Mann-Kendall检验:应用MK检验来评估ET趋势的统计显著性。检验结果以元分类图呈现,标明ET变化的显著性,帮助识别出有显著变化的区域。 3.重分类结果:通过重分类处理,将区域根据ET变化的显著性进行分类,从而聚焦于具有显著变化的区域。这一过程确保分析集中在具有实际意义的发现上。 4.最终输出:最终结果以栅格图和png图的形式呈现,支持各种应用,包括政策规划、水资源管理和土地利用变化分析,这些都是基于详细的时空分析。 ------------------------------------------------------------------- 文件夹构造: data文件夹:原始数据,支持分析的基础数据(MOD16A2H ET数据 宁夏部分)。 results文件夹:分析结果与可视化,展示研究成果。 Sen+MK_optimized.py:主分析脚本,适合批量数据处理和自动化分析。 Sen+MK.ipynb:Jupyter Notebook,复现可视化地图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值