#include<cstdio>
#include<iostream>
#include<string>
#include<cstdlib>
#define maxn 10
using namespace std;
struct
Tri
{

Tri*next[maxn];
int
num;
};

Tri *root;
void
buildTri(string ss)//建树的过程是一个动态的过程 动插的过程
{
Tri *p=root,*q;
for
(int i=;i<ss.size();i++)
{

int
id=ss[i]-'0';
if
(p->next[id]==NULL)
{

q=(Tri*)malloc(sizeof(Tri));
q->num=;
for
(int j=;j<maxn;j++) q->next[j]=NULL;
p->next[id]=q;
p=p->next[id];
}

else
p=p->next[id],p->num++;
}

p->num=-;// 作为结束的标志
}
int
findTri(string ss)
{

Tri *p=root,*q;
for
(int i=;i<ss.size();i++)
{

int
id=ss[i]-'0';
p=p->next[id];
if
(p==NULL) return;
if
(p->num==-) return -;
}

return
-;
}

void
del(Tri *root)
{

Tri *zz=root;
if
(zz==NULL) return;
for
(int i=;i<maxn;i++)
{

if
(zz->next[i]!=NULL) del(zz->next[i]);
}

free(zz);
}

int
main()
{

int
t;
cin>>t;
while
(t--)
{

root=(Tri*)malloc(sizeof(Tri));
for
(int i=;i<maxn;i++) root->next[i]=NULL;
root->num=;
int
ret;
cin>>ret;
string ss;
int
flag=;
while
(ret--)
{

cin>>ss;
if
(findTri(ss)==-) flag=;
// cout<<flag<<endl;
buildTri(ss);
}

del(root);
if
(flag) cout<<"YES"<<endl;
else
cout<<"NO"<<endl; }
return
;
}

hdu 1671 复习字典树的更多相关文章

  1. HDU 1671 (字典树统计是否有前缀)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem Description Given a list of phone number ...

  2. hdu杭电1671 / poj3630 字典树

    传送门 题意:输入n串数字 找出是否有存在串的前缀与另一个串相同 如果存在 输出NO否则输出YES 思路:用字典树解决 标记字典树总串的结尾 查找出一个串内部是否有被标记的节点 如果有那么说明存在前缀 ...

  3. hdu 1979 DFS + 字典树剪枝

    http://acm.hdu.edu.cn/showproblem.php?pid=1979 Fill the blanks Time Limit: 3000/1000 MS (Java/Others ...

  4. hdu 2846(字典树)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  5. HDU 2846 Repository (字典树 后缀建树)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  6. HDU 2846 Repository(字典树,标记)

    题目 字典树,注意初始化的位置~!!位置放错,永远也到不了终点了org.... 我是用数组模拟的字典树,这就要注意内存开多少了,,要开的不大不小刚刚好真的不容易啊.... 我用了val来标记是否是同一 ...

  7. *hdu 5536(字典树的运用)

    Input The first line of input contains an integer T indicating the total number of test cases. The f ...

  8. three arrays HDU - 6625 (字典树)

    three arrays \[ Time Limit: 2500 ms \quad Memory Limit: 262144 kB \] 题意 给出 \(a\),\(b\) 数组,定义数组 \(c[i ...

  9. HDU 6625 (01字典树)

    题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中: ...

随机推荐

  1. 【面试题总结】1、统计字符串中某个字符出现的次数(2-Python实现)

    1.可以使用Python的字典实现,对于一个特定的字符串,使用for循环遍历其中的字符,并保存成字典形式.字典的key为字符,value为字符在整个字符串中出现的次数. 2.拓展:如果题目为比较两个字 ...

  2. MySQL:数据库名或者数据表名包含-

    [参考文章]:mysql数据库名称中包含短横线的对应方式 1. 现象 命令行下操作 名称包含 " - " 数据库或者数据表时,语句执行报错: 2. 解决方案: 使用 `` 字符(E ...

  3. SCRIPT438: 对象不支持“trim”属性或方法

    关于ie9以下不支持trim()方法 可以在自己封装的框架中加入如下.或直接调用也行. if(!String.prototype.trim) { String.prototype.trim = fun ...

  4. Hearthstone AI

    search keyword `machine learning hearthstone` with google I am a legend: Hacking Hearthstone with ma ...

  5. Memcache启动停止

    启动Memcached root -P /var/run/memcached.pid 1)启动参数说明: -d 选项是启动一个守护进程, -l 是监听的服务器IP地址,默认为所有网卡. -p 是设置M ...

  6. mongoose 建立schema 和model

    在node中使用MongoDB很多情况下,都是使用mongoose的,所以这集来介绍一下 安装 yarn add mongoose 连接 const mongoose = require(" ...

  7. Python升级提示Tkinter模块找不到的解决方法

    一.安装tkinter在Linux中python默认是不安装Tkinter模块,复制代码 代码如下:[root@li250-193 ~]# pythonPython 2.6.6 (r266:84292 ...

  8. JAVA 基础编程练习题39 【程序 39 分数累加】

    39 [程序 39 分数累加] 题目:编写一个函数,输入 n 为偶数时,调用函数求 1/2+1/4+...+1/n,当输入 n 为奇数时,调用函数 1/1+1/3+...+1/n package cs ...

  9. Elasticsearch删除数据操作,你必须知道的一些坑

    前两天有同事打电话问我,说ES删除数据有没有什么坑? 我当时就问,是删索引还是删索引里的数据?她回答说是删数据,我说查出这些数据直接删除就好了,没有什么坑... 后来想想,关于ES数据的删除,之前确实 ...

  10. centos(linux)-jdk配置

    1.清理系统默认自带的jdk 在安装centos时,可能系统会默认安装了例如openjdk等,需要先手动卸载 先执行:rpm -qa | grep jdk (查看已经自带的jdk): 卸载命名:sud ...