这题看是否

这题能A是侥幸,解决的办法是先存一下输入的字符串,进行排序。

Problem Description
An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the prefix of a code for another symbol. We will assume for this problem that all codes are in binary, that no two codes within a set of codes are the same, that each code has at least one bit and no more than ten bits, and that each set has at least two codes and no more than eight.
Examples: Assume an alphabet that has symbols {A, B, C, D}
The following code is immediately decodable: A:01 B:10 C:0010 D:0000
but this one is not: A:01 B:10 C:010 D:0000 (Note that A is a prefix of C)
Input
Write a program that accepts as input a series of groups of records from input. Each record in a group contains a collection of zeroes and ones representing a binary code for a different symbol. Each group is followed by a single separator record containing a single 9; the separator records are not part of the group. Each group is independent of other groups; the codes in one group are not related to codes in any other group (that is, each group is to be processed independently).
Output
For each group, your program should determine whether the codes in that group are immediately decodable, and should print a single output line giving the group number and stating whether the group is, or is not, immediately decodable.
Sample Input
01 10 0010 0000 9 01 10 010 0000 9
Sample Output
Set 1 is immediately decodable Set 2 is not immediately decodable

#include <iostream>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

using namespace std;

typedef struct Node

{

struct Node *next[2];

int flag;

}Node,*Tree;

int flag1;

void Creat(Tree &T)

{

T=(Node *)malloc(sizeof(Node));

T->flag=0;

for(int i=0;i<2;i++)

T->next[i]=NULL;

}

void insert(Tree &T,char *s)

{

Tree p=T;

int t;

int l=strlen(s);

for(int i=0;i<l;i++)

{

t=s[i]-'0';

if(p->next[t]==NULL)

Creat(p->next[t]);

p=p->next[t];

if(p->flag>0)

flag1=0;

}

p->flag++;

}

void D(Tree p)

{

for(int i=0;i<2;i++)

{

if(p->next[i]!=NULL)

D(p->next[i]);

}

free(p);

}

int main()

{

char a[30];

int kk=0;

Tree T;

while(scanf("%s%*c",a)!=EOF)

{

Creat(T);

kk++;

flag1=1;

insert(T,a);

while(scanf("%s",a)!=EOF)

{

if(strcmp(a,"9")==0)

break;

insert(T,a);

}

if(flag1)

printf("Set %d is immediately decodable\n",kk);

else printf("Set %d is not immediately decodable\n",kk);

D(T);

}

return 0;

}

hdu1305Immediate Decodability(字典树)相关推荐

  1. HDU-1305-Immediate Decodability

    HDU-1305-Immediate Decodability http://acm.hdu.edu.cn/showproblem.php?pid=1305 字典树水题,判断前缀 #include&l ...

  2. 提高篇 第二部分 字符串算法 第3章 Trie字典树

    Trie(字典树)解析及其在编程竞赛中的典型应用举例 - Reqaw - 博客园 『一本通』Trie字典树 - YeLingqi - 博客园 字典树(Trie Tree) - 仰望高端玩家的小清新 - ...

  3. hdu5296 01字典树

    根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespa ...

  4. BZOJ 3483 SGU505 Prefixes and suffixes(字典树+可持久化线段树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3483 [题目大意] 给出一些串,同时给出m对前缀后缀,询问有多少串满足给出的前缀后缀模 ...

  5. 2014百度之星 Xor Sum(字典树+贪心)

    题目在HDU_OJ Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometh ...

  6. HDU6964 I love counting (字典树+莫队)

    题意: 给定一个长度为 nnn 的序列c,qc,qc,q 次询问,每次给出l,r,a,bl,r,a,bl,r,a,b求在[l,r][l,r][l,r]中有多少种不同的值 kkk 满足 k⊕a≤b​.k ...

  7. Beautiful Subarrays (01字典树 瞎搞)

    题意: 题解: 一看问的是子序列,并且还是异或. 首先想到01字典树,再一看让你求子序列的个数,大致是想让你把这个序列进行前缀异或处理后然后再01字典树上进行操作吧. 假设01字典树往左边是0右边是1 ...

  8. CF888G Xor-MST (01字典树+MST)

    题意: 给你n个数,每个数有一个值. 问你这n个数的最小生成树为多少,两点之间的边权为异或值. 题解: 参考了洛谷上的一个题解,总觉得这样的时间复杂度会爆炸,但是确确实实没爆炸. 我们每次去合并两个点 ...

  9. Perfect Security (01字典树删除点)

    题意: 第一行给你一个n 第二行给你n个数字 分别是a[1],a[2]-a[n]. 第三行给你n个数字 分别是b[1],b[2]-b[n]. 问:第三行的序列可自由排列,要求排列之后的顺序 a[1] ...

最新文章

  1. 春节假期延长了,这里给你推荐几本2020年不容错过的机器学习书籍!
  2. html中::before 爬虫_反反爬虫系列(四)
  3. keras画acc和loss曲线图
  4. c++中报错预处理器指令后有意外标记 - 应输入换行符
  5. Mac上在终端上解压与压缩
  6. Jmeter_前端RSA加密下的登陆模拟_引用js文件实现(转)
  7. 2019年第十届蓝桥杯 - 省赛 - C/C++大学B组 - D. 数的分解
  8. Go Modules 的智障版本选择
  9. Newbe.Claptrap-一套以“事件溯源”和“Actor模式”作为基本理论的服务端开发框架...
  10. java arraycopyof_Java中System.arraycopy()和Arrays.copyOf()的区别
  11. hbase多master和动态添加节点
  12. 你心中有这样的人吗?
  13. 迷宫求解 java_迷宫求解算法(java版)
  14. 看懂友盟指数,洞察移动行业大趋势
  15. 【GNN】图神经网络的解释性综述
  16. MatLab数字图像处理实战(赵小川)-sift原理
  17. 如何评价杭州阿里、海康、网易等组成 HR 联盟?
  18. maven的pom文件引入依赖报错:提示无法处理 Cannot resolve...
  19. HITCS_大作业_程序人生-Hello’s P2P
  20. 操作Excel导入的问题(转)

热门文章

  1. android相机采集sdk,Android相机在Android SDK怪怪
  2. java collections_Java集合基础的详细介绍(二)
  3. 图片转字符 android,转字符图app下载-转字符图 安卓版v2.4-PC6安卓网
  4. mysql 4.1.10_Mysql4.1.10初级解读
  5. Java学习总结:51(对象序列化)
  6. Java学习总结:12
  7. python函数手册68_直接在python中检索68个内置函数?
  8. 单链表逆序生成及逆置的完整实现
  9. 一些有趣的题目(java)持续更新
  10. JS对象直接量,数组直接量和函数直接量