poj3630 简单Trie
来源:互联网 发布:windows 开发ios 编辑:程序博客网 时间:2024/06/10 13:39
突然想到一个很机智的做法,mark,插入的时候直接返回最后一个的sz,然后插入完之后判断一下就好啦、
// Created by Chenhongwei in 2015.// Copyright (c) 2015 Chenhongwei. All rights reserved.#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <climits>#include <queue>#include <cmath>#include <map>#include <set>#include <stack>#include <vector>#include <sstream>#include <algorithm>using namespace std;const int inf=1e9;const int maxn=1e5+100;typedef long long ll;typedef unsigned long long ull;int ch[100100][10];int v[10010],sz,n;char s[10010][15];int insert(int x){int u=0,len=strlen(s[x]);for(int i=0;i<len;i++){int c=s[x][i]-'0';if(!ch[u][c]){memset(ch[sz],0,sizeof ch[sz]);ch[u][c]=sz++;}u=ch[u][c];}return u;}int main(){//ios::sync_with_stdio(false);// freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int T;scanf("%d",&T);while(T--){sz=1;memset(ch,0,sizeof ch);scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%s",s[i]);v[i]=insert(i);}bool ok=0;for(int i=1;i<=n;i++)for(int j=0;j<=9;j++)if(ch[v[i]][j]){ok=1;break;}if(ok)printf("NO\n");elseprintf("YES\n");}return 0;}
0 0
- poj3630 简单Trie
- Phone List(poj3630,简单trie树)
- POJ3630(Trie树)
- Trie树 poj3630
- POJ3630(Trie树)
- POJ3630 静态建立trie
- POJ3630 trie字典树水题
- POJ3630(Trie树)
- poj3630 Phone List与Trie
- POJ3630 Phone List 静态Trie || Qsort
- Trie树(字典树)poj3630+hdu1671
- POJ3630(Trie树) PHONE LIST 算法转载
- poj3630
- poj3630
- poj3630
- ZOJ2876 POJ3630 HDU1671 Phone List,静态Trie树
- HihoCoder第二周与POJ3630:Trie树的建立
- C++——字典树(Trie树)例题——Phone List(POJ3630)(HDU1671)
- 联想M490原装Win8系统改Win7系统的血泪史
- 线程中的一些常用方法的用法 join()、yield()、sleep()、wait()、notify()、notifyAll()
- 认真的第一天_JAVA环境变量配置小细节
- OpenJudge1413 Mondriaan's Dream
- VWware workstation 虚拟机安装VWware Tools 的过程(初学时用)
- poj3630 简单Trie
- manacher算法
- LLVM学习笔记
- git reset
- HDU4417
- 【数据结构】逆波兰表达式
- 蓝桥杯——十进制转十六进制
- PHP实现访客计数器
- 2015NOIP模拟赛(二) 试题及解析