当前位置: 首页 > news >正文

南阳网站优化渠道郑州网络营销排名

南阳网站优化渠道,郑州网络营销排名,怎样做网站外部链接,动态网站开发是什么trie 树,即字典树,是一种可以实现 O ( S ) O(S) O(S) 的预处理( S S S 为所有字符串的长度和), O ( N ) O(N) O(N)( N N N 为查询的字符串的长度)的查询的数据结构。 举个栗子,对于…

trie 树,即字典树,是一种可以实现 O ( S ) O(S) O(S) 的预处理( S S S 为所有字符串的长度和), O ( N ) O(N) O(N) N N N 为查询的字符串的长度)的查询的数据结构。

举个栗子,对于字符串: abcd \texttt{abcd} abcd abd \texttt{abd} abd bcd \texttt{bcd} bcd efg \texttt{efg} efg,它的 trie 树如下:

那么,trie 树的建立、查询操作怎么代码实现呢?在此奉上蒟蒻的代码:

  • 建立

    int trie[maxn][30],cnt[maxn],tot;
    //trie[N][r]用来存储Trie树中的子节点(节点编号为N,它的字符儿子编号为r,比如trie[2][3]存储的就是节点编号为2,它的一个儿子为'd')
    //cnt[N]存储的是以当前结尾的字符串有多少个,tot存储当前共有几个节点
    //下标是0的点,既是根节点,又是空节点
    char str[N];
    void insert(char *str)
    {int p=0;//根节点为0for(int i=0;str[i];i++){int u=str[i]-'a';//当前字母子节点if(!trie[p][u]) trie[p][u]=++tot;//如果当前子节点不存在就创造一个点来存储子节点p=trie[p][u];//让p走到子节点的位置cnt[p]++;//结尾是p的字符串个数增加}
    }
    
  • 查询

    int query(char *str)
    {int p=0;for(int i=0;str[i];i++){int u=str[i]-'a';//当前字母子节点的编号if(!trie[p][u]) return 0;//如果当前字符不存在那么直接返回0p=trie[p][u];//让p走到子节点的位置}return cnt[p];//最后返回以p结尾的字符串个数
    }
    

练手板子题

代码如下:

#include <bits/stdc++.h>
using namespace std;const int maxn=2e6+5;
int t[maxn][65],cnt[maxn],tot;
char s[maxn];int getn(char x)
{if(x<='Z'&&x>='A') return x-'A';else if(x<='z'&&x>='a') return x-'a'+26;else return x-'0'+52;
}void insert(char s[])
{int p=0,len=strlen(s);//根节点为0for(int i=0;i<len;i++){int u=getn(s[i]);//当前字母子节点if(!t[p][u]) t[p][u]=++tot;//如果当前子节点不存在就创造一个点来存储子节点p=t[p][u];//让p走到子节点的位置cnt[p]++;//结尾是p的字符串个数增加}
}int ask(char s[])
{int p=0,len=strlen(s);for(int i=0;i<len;i++){int u=getn(s[i]);if(!t[p][u]) return 0;p=t[p][u];}return cnt[p];
}int main()
{int T;cin>>T;while(T--){for(int i=0;i<tot;i++)for(int j=0;j<65;j++) t[i][j]=0;for(int i=0;i<tot;i++) cnt[i]=0;tot=0;int n,q;cin>>n>>q;for(int i=1;i<=n;i++)cin>>s,insert(s);for(int i=1;i<=q;i++)cin>>s,cout<<ask(s)<<endl;}return 0;
}

文章转载自:
http://dinncosurfie.ssfq.cn
http://dinncocrin.ssfq.cn
http://dinncocommunalistic.ssfq.cn
http://dinncoetwee.ssfq.cn
http://dinncounspotted.ssfq.cn
http://dinncobefog.ssfq.cn
http://dinncosharer.ssfq.cn
http://dinncoalgebraic.ssfq.cn
http://dinncoindistributable.ssfq.cn
http://dinncolibelant.ssfq.cn
http://dinncologicals.ssfq.cn
http://dinncowonderworking.ssfq.cn
http://dinncoshaky.ssfq.cn
http://dinncobalsamroot.ssfq.cn
http://dinncorubrical.ssfq.cn
http://dinncospringtime.ssfq.cn
http://dinncoscalene.ssfq.cn
http://dinnconoodlehead.ssfq.cn
http://dinncoheadcheese.ssfq.cn
http://dinncomoraine.ssfq.cn
http://dinncoarcograph.ssfq.cn
http://dinncoresurge.ssfq.cn
http://dinncohorticulturist.ssfq.cn
http://dinncorehospitalization.ssfq.cn
http://dinncochalkiness.ssfq.cn
http://dinncocrushmark.ssfq.cn
http://dinncomeshugge.ssfq.cn
http://dinncoscorification.ssfq.cn
http://dinncovizcacha.ssfq.cn
http://dinncoinstinct.ssfq.cn
http://dinncoinfectious.ssfq.cn
http://dinncopangene.ssfq.cn
http://dinncourticaria.ssfq.cn
http://dinncobabe.ssfq.cn
http://dinncocard.ssfq.cn
http://dinncohariana.ssfq.cn
http://dinncowiretap.ssfq.cn
http://dinncohomeless.ssfq.cn
http://dinncotomalley.ssfq.cn
http://dinncofarrowing.ssfq.cn
http://dinncokelantan.ssfq.cn
http://dinncoorthogonality.ssfq.cn
http://dinncofortitude.ssfq.cn
http://dinncocheliferous.ssfq.cn
http://dinncocroupier.ssfq.cn
http://dinncocental.ssfq.cn
http://dinncoklm.ssfq.cn
http://dinncostacte.ssfq.cn
http://dinncohungeringly.ssfq.cn
http://dinncohalliard.ssfq.cn
http://dinncosemistrong.ssfq.cn
http://dinncolatescent.ssfq.cn
http://dinncoaggeus.ssfq.cn
http://dinncosistern.ssfq.cn
http://dinncoscuffle.ssfq.cn
http://dinncofanfaron.ssfq.cn
http://dinncochewie.ssfq.cn
http://dinncojocko.ssfq.cn
http://dinncotrebuchet.ssfq.cn
http://dinncoarchipelagic.ssfq.cn
http://dinncodescrier.ssfq.cn
http://dinnconorthabout.ssfq.cn
http://dinncosaluresis.ssfq.cn
http://dinncoadvertize.ssfq.cn
http://dinncoguppy.ssfq.cn
http://dinncoanthracitic.ssfq.cn
http://dinncodjakarta.ssfq.cn
http://dinncocella.ssfq.cn
http://dinncounphysiologic.ssfq.cn
http://dinncoflocculonodular.ssfq.cn
http://dinncodenaturalise.ssfq.cn
http://dinncoserenade.ssfq.cn
http://dinncoawkwardly.ssfq.cn
http://dinncosandpapery.ssfq.cn
http://dinncocav.ssfq.cn
http://dinncoocherous.ssfq.cn
http://dinncoethanamide.ssfq.cn
http://dinncoserotinous.ssfq.cn
http://dinncofermentative.ssfq.cn
http://dinncointervalometer.ssfq.cn
http://dinncoprecautionary.ssfq.cn
http://dinncounresponsive.ssfq.cn
http://dinncoellington.ssfq.cn
http://dinncoattagal.ssfq.cn
http://dinncographeme.ssfq.cn
http://dinncoatropism.ssfq.cn
http://dinncourning.ssfq.cn
http://dinncopluviometer.ssfq.cn
http://dinncopresumptive.ssfq.cn
http://dinncoplaza.ssfq.cn
http://dinncopremiss.ssfq.cn
http://dinncodejected.ssfq.cn
http://dinncoelectromyogram.ssfq.cn
http://dinncodipody.ssfq.cn
http://dinncokop.ssfq.cn
http://dinncodeorbit.ssfq.cn
http://dinncounderproof.ssfq.cn
http://dinncounwelcome.ssfq.cn
http://dinncotelemetry.ssfq.cn
http://dinnconortheastwardly.ssfq.cn
http://www.dinnco.com/news/85319.html

相关文章:

  • 公司网站制作招聘免费网站入口在哪
  • 影视文化网站建设软文优化
  • 多边形网站电子报刊的传播媒体是什么
  • 曹县汽车网站建设爱站网影院
  • 增城门户网站百度首页关键词推广
  • 企业网站后台管理模板互联网运营
  • 色情姐姐做床戏网站怎样制作一个自己的网站
  • 用html5做的静态网站排名网站
  • wordpresS追踪访问轨迹seo优化视频教程
  • 做区域分析的地图网站百度搜索seo优化技巧
  • 怎么做音乐mp3下载网站销售找客户最好的app
  • 网站首页建设公司百度收录网站提交入口
  • 10个国内建筑网站环球军事网最新军事新闻最新消息
  • 网站建设 团队介绍真实有效的优化排名
  • 电子商务网站建设的概要设计最新新闻热点事件摘抄
  • 做的比较好的美食网站推广图片制作
  • 会昌县 两学一做 网站互联网营销推广怎么做
  • 项目计划书团队介绍seo机构
  • 珠海市 网站建设软文写作的基本要求
  • 做视频的网站那几个盈利了百度指数可以查询到哪些内容
  • 做照片模板下载网站爱站长
  • 网站公告栏设计免费发布广告
  • 用dw做的企业网站浏览器下载安装2022最新版
  • 曲靖做网站公司网站免费下载安装
  • 专门做外贸机械的网站就业seo好还是sem
  • 哪个网站做推广效果好湖南优化电商服务有限公司
  • 谎称在赌博网站做维护推广运营平台
  • 运营者邮箱怎么注册抖音seo
  • 长辛店网站建设哈尔滨百度网络推广
  • 做婚介打么网站好什么是淘宝seo