#include<cstdio>
#include<iostream>
#include<string>
#include<cstdlib>
#define maxn 2
#include<queue>
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
Case=;
string ss;
queue<string> fuck;
while
(cin>>ss)
{

if
(ss=="9")
{

int
flag=;
root=(Tri *)malloc(sizeof(Tri));
for
(int i=;i<maxn;i++) root->next[i]=NULL;
root->num=;
while
(!fuck.empty())
{

string temp;
temp=fuck.front();
fuck.pop();
if
(findTri(temp)==-)
{

flag=;
break
;
}

buildTri(temp);
}

if
(flag) printf("Set %d is immediately decodable\n",++Case);
else
printf("Set %d is not immediately decodable\n",++Case);
del(root);
continue
;
}

fuck.push(ss);
}

return
;
}

hdu 1305 还是字典树的更多相关文章

  1. hdu 1979 DFS + 字典树剪枝

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

  2. hdu 2846(字典树)

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

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

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

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

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

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

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

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

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

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

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

  8. HDU 6625 (01字典树)

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

  9. HDU 1298 T9 ( 字典树 )

    题意 : 给你 w 个单词以及他们的频率,现在给出模拟 9 键打字的一串数字,要你在其模拟打字的过程中给出不同长度的提示词,出现的提示词应当是之前频率最高的,当然提示词不需要完整的,也可以是 w 个单 ...

随机推荐

  1. Flask 编写一个授权登录验证的模块(二)

    本篇比上一篇多了重定向的功能 #!/usr/bin/env python # -*- coding: utf-8 -*- #python3 import base64 import random im ...

  2. 数据库groub by分组后,把多行数据合并成一行数据(Oracle、Postgres)

    关键字 row_number() over (partition by)   例如,下面的数据, 这是按照name分组后,展示property值. 我们想得到这样的值; 第一步:将每一组的proper ...

  3. 使用es6一句话去重

    let arr = [1,2,3,4,5,1,2,3] let arr2 = Array.from(new Set(arr)) console.log(arr2) //[1,2,3,4,5]

  4. linux 查看网络流量命令

    转: linux 查看网络流量命令 2019年01月31日 14:22:00 weixin_33894992 阅读数 893   sar命令参数很多,有时间man一下. -n参数很有用,他有6个不同的 ...

  5. C++ STL Heap算法

    #include <iostream>#include <algorithm>#include <vector> using namespace std; int ...

  6. 参照UB单创建DN并过账

    *&---------------------------------------------------------------------* *& Form FRM_DN_POST ...

  7. python md5验签

    import hashlib #api验签 参数按首字母排序,然后拼接clientid=123456&num=xxxx&status=1&timestamp=157319776 ...

  8. tf.contrib.layers.fully_connected参数笔记

    tf.contrib.layers.fully_connected 添加完全连接的图层. tf.contrib.layers.fully_connected(    inputs,    num_ou ...

  9. 基于Keras 的VGG16神经网络模型的Mnist数据集识别并使用GPU加速

    这段话放在前面:之前一种用的Pytorch,用着还挺爽,感觉挺方便的,但是在最近文献的时候,很多实验都是基于Google 的Keras的,所以抽空学了下Keras,学了之后才发现Keras相比Pyto ...

  10. OpenCV.物体识别

    1.度娘:“OpenCV 物体识别” 1.1.opencv实时识别指定物体 - 诺花雨的博客 - CSDN博客.html(https://blog.csdn.net/qq_27063119/artic ...