hiho 1014 trie树
来源:互联网 发布:python ruby 哪个好 编辑:程序博客网 时间:2024/06/08 02:15
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=1e6+5;struct node{ int next[26]; int cnt; void init() { cnt=0; memset(next,-1,sizeof(next)); }}a[maxn];int cnt;char s[15];void update(){ int now,pos; now=pos=0; while(s[now]) { if(a[pos].next[s[now]-'a']==-1) { a[cnt].init(); a[pos].next[s[now]-'a']=cnt++; } pos=a[pos].next[s[now]-'a']; a[pos].cnt++; now++; }}void ask(){ int now,pos; now=pos=0; while(s[now]) { if(a[pos].next[s[now]-'a']==-1) { printf("0\n"); return; } pos=a[pos].next[s[now]-'a']; now++; } printf("%d\n",a[pos].cnt);}int main(){ int n,m,i; scanf("%d",&n); cnt=1;//找了一个公共节点 a[0].init(); for(i=0;i<n;i++) { scanf("%s",s); update(); } scanf("%d",&m); for(i=0;i<m;i++) { scanf("%s",s); ask(); } return 0;}
阅读全文
0 0
- HiHo 1014 Trie树
- hiho 1014 : Trie树
- hiho#1014-Trie树
- hiho 1014 trie树
- hiho一下第二周#1014 : Trie树
- hiho一下 Trie树
- hiho 2 Trie树
- hihocoder Trie树 hiho题库 #1014 : Trie树
- hiho-1014 Trie树 (Trie的建树与查询)
- hiho 第二周 trie树
- HIHO Trie树入门练习
- hiho一下第二周 Hihocoder #1014 : Trie树
- (hiho一下第二周)#1014 Trie树 【模版】
- 【hiho一下】第二周 Trie树
- hiho一下第二周 Trie树
- hiho一下第二周:Trie树
- hiho第二周——Trie树
- hiho一下第二周Trie树 题解
- 排序算法之选择排序
- Sklearn 中的 GridSearchCV
- Hexo博客搭建之使用Hexo+GitHub搭建个人博客
- Java并发实战:CountDownLatch实现多线程抽题
- 斐波那契数列Fibonacci实现(递归、尾递归、循环)
- hiho 1014 trie树
- 如何查看Linux是32位还是64位
- 拉斯维加斯枪击事件警方调查结果
- Netty5--入门
- 如果看了此文你还不懂傅里叶变换,那就过来掐死我吧【完整版】
- -bash: /tyrone/jdk/jdk1.8.0_91/bin/java: cannot execute binary file
- STL-map容器
- lintcode加一
- python 逻辑符号及循环