POJ 3630 Trie树
来源:互联网 发布:淘宝生意参谋网址手机 编辑:程序博客网 时间:2024/05/19 14:55
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 101000
struct st{
bool isLeaf;
int next[10];
}trie[N];
int nodep;
int root;
int new_node()
{
memset(trie[nodep].next,-1,sizeof(trie[nodep].next));
trie[nodep].isLeaf = false;
nodep++;
return nodep-1;
}
void trie_init()
{
nodep = 0;
root = new_node();
}
bool trie_find_insert(char phone[])
{
int node = root;
bool new_branch = false;
for(int i=0;phone[i];i++){
int ki = phone[i]-'0';
if(trie[node].next[ki]==-1){
new_branch = true;
trie[node].next[ki] = new_node();
}
node = trie[node].next[ki];
if(trie[node].isLeaf) return true;
}
trie[node].isLeaf = true;
if(new_branch) return false;
else return true;
}
int main()
{
int t; scanf("%d",&t);
while(t--){
int n; scanf("%d",&n); getchar();
trie_init();
bool found = false;
char phone[12];
for(int i=0;i<n;i++){
gets(phone);
if(!found) found = trie_find_insert(phone);
}
if(!found) puts("YES");
else puts("NO");
}
// system("pause");
return 0;
}
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 101000
struct st{
bool isLeaf;
int next[10];
}trie[N];
int nodep;
int root;
int new_node()
{
memset(trie[nodep].next,-1,sizeof(trie[nodep].next));
trie[nodep].isLeaf = false;
nodep++;
return nodep-1;
}
void trie_init()
{
nodep = 0;
root = new_node();
}
bool trie_find_insert(char phone[])
{
int node = root;
bool new_branch = false;
for(int i=0;phone[i];i++){
int ki = phone[i]-'0';
if(trie[node].next[ki]==-1){
new_branch = true;
trie[node].next[ki] = new_node();
}
node = trie[node].next[ki];
if(trie[node].isLeaf) return true;
}
trie[node].isLeaf = true;
if(new_branch) return false;
else return true;
}
int main()
{
int t; scanf("%d",&t);
while(t--){
int n; scanf("%d",&n); getchar();
trie_init();
bool found = false;
char phone[12];
for(int i=0;i<n;i++){
gets(phone);
if(!found) found = trie_find_insert(phone);
}
if(!found) puts("YES");
else puts("NO");
}
// system("pause");
return 0;
}
- POJ 3630 Trie树
- POJ 3630 Trie树
- poj 3630 trie树
- POJ 3630 trie树
- POJ 3630 trie树模板
- poj 3630 trie树 基本使用
- POJ 3630 Phone List 【Trie树入门】
- POJ 3630 - Phone List (Trie树)
- poj 3630 Trie树, WA到想哭了
- POJ -- 3630 Phone List(Trie 树)
- POJ 3630 解题报告 Trie 树
- poj 3630 找重复前缀 trie树
- [poj 3630] Phone List trie 树
- POJ 3630 --Trie
- poj 3630(trie)
- Trie树 POJ 1056
- POJ 2001 Trie树
- poj 2001 trie 树
- bash shell 遍历指定目录下文件 iconv 编码转换
- 分布式密码分析框架-Wisecracker
- NEFU要崛起——第3场
- CSS行高:line-height属性详解
- linux下的mysql命令
- POJ 3630 Trie树
- C++对象模型《Inside the C++ Object Model》
- POJ3349 重复的雪花(数字哈希)
- Shortest path of the king(比赛2.A)
- web访问ejb测试 详解
- 算法导论第六章 堆排序
- 类似网易新闻客户端首页的图片浏览,右下角显示当前第几个图片
- ModelGoon安装
- 监控系统中的消息通道设计小结