字典树
来源:互联网 发布:网络摄像头哪个牌子好 编辑:程序博客网 时间:2024/05/21 09:51
字典树模板
poj3630
#include <cstdio>#include <algorithm>#include<cmath>#include<string.h>#include<memory.h>#include<iostream>#include<vector>#include<queue>#include<map>#include <stdio.h>#include <stack>#include <set>#define MOd 0x7FFFFFFF;#define mod 65537;using namespace std;typedef long long LL;const int N=1e9+7;char ss[10005][15];int t,n;struct tnode{int cnt;tnode *next[15];}root,node[100005];int num=0;tnode *inittree(){tnode *p=&node[num++];p->cnt=0;for(int i=0;i<10;i++) p->next[i]=NULL;return p;}void maketree(tnode *&root,char *p){if(root==NULL ) root=inittree();tnode *t=root;while(*p){ if(t->next[*p-'0']==NULL){ t->next[*p-'0']=inittree(); } t=t->next[*p-'0']; t->cnt++; p++;}}bool seah(tnode *root,char *p){//cout<<"r"<<endl;//cout<<p<<endl;if(root==NULL)return true;//cout<<"r"<<endl;tnode *t=root;while(*p){ //cout<<"r"<<endl; //cout<<*p<<"p"<<endl; t=t->next[*p-'0']; //cout<< t->cnt <<" "<<*p<<endl; p++;}if(t->cnt>1) return false;else return true;}int main(){ // freopen("in.txt","r",stdin);cin>>t;tnode *root=NULL;while(t--){ root=NULL; scanf("%d",&n); int i; for(i=0;i<n;i++){ scanf("%s",ss[i]); maketree(root,ss[i]); } for(i=0;i<n;i++){ if(!seah(root,ss[i])){ cout<<"NO"<<endl; break; } } if(i==n) cout<<"YES"<<endl;num=0;}return 0;}
0 0
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树。。
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- hdu3400 _嵌套三分 三分求极限
- hdu1698 Just a Hook(成段更新+懒惰标记)
- fnmatch模块的使用
- 最大映射
- poj 3608(旋转卡壳求解两凸包之间的最短距离)
- 字典树
- hdoj1025Constructing Roads In JGShining's Kingdom【LIS】
- 我的第一个嵌入式linux驱动(基于韦东山led驱动)
- [linux]查看端口号占用情况
- IOS学习 绘图 UIBezierPath 绘基本图形、样式设置、渲染填充
- 运算器的特殊实现方法
- hdoj1078FatMouse and Cheess【记忆化搜索】
- 深度优先搜索DFS
- Hamx安装失败的问题