#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. StringUtils的isNotEmpty,isNotBlank方法的区别

    这两个用着用着老是混淆或者忘记,今天写一下做个笔记,对比下两个判断方法的区别 isNotEmpty: 判断某字符串是否非空,等于!isEmpty(String str),这里不能排除空格字符 Stri ...

  2. golang入门time与string转换, time加减时间, 两个时间差

    package main import ( "fmt" "time") var timeLayoutStr = "2006-01-02 15:04:0 ...

  3. mysql 误删除所有用户或者忘记root密码

    /etc/init.d/mysqld stop //停止数据库/etc/init.d/mysqld restart //启动数据库(1)开启特殊启动模式mysqld_safe --skip-grant ...

  4. Thymeleaf th:include、th:replace引用

    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" ...

  5. Job for keepalived.service failed because the control process exited with error code. See "systemctl status keepalived.service" and "journalctl -xe" for details.

    解决方案 https://blog.csdn.net/zt15732625878/article/details/86493096

  6. BGP多线 有些BGP IP也会被极少数运营商劫持 取Ip逻辑

    小结: 1.租用的服务器只有一个IP,用户的访问路线是由路由器根据访客的实际访问速度选择最优访问路径,来选择访问的.而且不占用任何的服务器资源.服务器的上行和下行都是有路由器来选择最佳的路线,所以这样 ...

  7. LC 981. Time Based Key-Value Store

    Create a timebased key-value store class TimeMap, that supports two operations. 1. set(string key, s ...

  8. OpenStack 虚拟机热迁移流程图

    目录 文章目录 目录 源计算节点与目的计算节点之间的交互流程 Nova 和 Neutron 之间的交互流程 源计算节点与目的计算节点之间的交互流程 热迁移主要包括三个阶段: pre_live_migr ...

  9. leetcode刷题-559. Maximum Depth of N-ary Tree

    题目: https://leetcode.com/problems/maximum-depth-of-n-ary-tree/description/ n-ary-tree的数据结果表示 // Defi ...

  10. 新maven项目创建JSP出现小红叉报错 javax.servlet.http.HttpServlet not found

    展示: 右击项目----build path -----Configure Build Path 进入到窗口 libraries -------add libraries ------  server ...