hihocoder 1014 Trie树
来源:互联网 发布:痘痘变硬了怎么办知乎 编辑:程序博客网 时间:2024/06/02 00:15
题目链接:Trie树
题目大意:给你n个字符串,m次询问,每次去询问给定的字符串是给定的字符串里面中多少个字符串的前缀
题目思路:字典树直接做就好了
#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <vector>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e6+10;int le;struct node{ int Next[26]; int cnt; void init(){ cnt = 0; memset(Next,-1,sizeof(Next)); }}T[maxn];void Insert(char *s){ int i = 0,p = 0; while(s[i]){ int x = s[i]-'a'; if(T[p].Next[x] == -1){ T[le].init(); T[p].Next[x] = le++; } p = T[p].Next[x]; T[p].cnt++; i++; }}void query(char *s){ int i = 0,p = 0; while(s[i]){ int x = s[i]-'a'; if(T[p].Next[x] == -1){ puts("0"); return ; } p = T[p].Next[x]; i++; } printf("%d\n",T[p].cnt);}int main(){ int n,m; char str[20]; while(~scanf("%d",&n)){ le = 1; T[0].init(); while(n--){ scanf("%s",str); Insert(str); } scanf("%d",&m); while(m--){ scanf("%s",str); query(str); } } return 0;}
阅读全文
0 0
- hihocoder 1014 Trie树 trie
- [hihoCoder 1014][Trie 树]Trie
- hihocoder 1014 trie树
- hihocoder#1014 : Trie树
- hihoCoder #1014 : Trie树
- [HiHoCoder]#1014 : Trie树
- hihoCoder#1014Trie树
- hihoCoder #1014 Trie树
- hihocoder-#1014 : Trie树
- hihoCoder 1014 : Trie树
- hihoCoder #1014 : Trie树
- hihocoder-#1014 : Trie树
- hihocoder #1014 trie 树
- hihoCoder - 1014 - Trie树
- hihoCoder 1014 Trie树
- hihocoder 1014 trie树
- HihoCoder 1014 : Trie树
- hihoCoder 1014Trie树
- CodeWarrior for S12X 调试器的D-Flash编程支持
- Codeforces Round #436 E.Fire(01背包 + 输出路径)
- ros的全局把握
- 2017年10月11日一点点人生感悟~人一定要靠自己
- 比较总结线性表的几种主要存储结果
- hihocoder 1014 Trie树
- hdu 5521 Meeting(优先队列+dijkstra)(建图思想)
- 手动部署 使用 bluestore 后端的 osd (L版)
- 【LeetCode】C# 39、Combination Sum
- CodeForces 868B Race Against Time
- Bootstrap 控制移动端和网页端的元素隐藏和显示
- node vue 环境搭建
- 使用js跨域获取数据的方法
- nkoj 1313(noip2007)树网的核 与 nkoj 2650(SDOI2011)消防