当前位置: 首页 > 编程日记 > 正文

hdu1305Immediate Decodability(字典树)

这题看是否

这题能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;

}

相关文章:

python isdigit()

isdigit(): Python isdigit() 方法检测字符串是否只由数字组成。如果字符串只包含数字则返回 True 否则返回 False。 实例 以下实例展示了isdigit()方法的实例&#xff1a; #!/usr/bin/python3str "123456"; print (str.isdigit()) str "Runoob example....wo…

Control Channel Element (CCE)

1. CCE是PDCCH的资源单元 (resourceunit)。 A PDCCH is transmitted on one CCE or anaggregation of several consecutive CCEs, where a CCE corresponds to 9 Resource ElementGroups (REGs). In PDCCH transmission, only those REGs are used which are notassigned …

phpstrom+xdebug调试PHP代码

众所周知开发PHP的IDE种类繁多&#xff0c;然而开发PHP并不能像开发其他语言一样&#xff0c;调试PHP代码对诸多新手来说&#xff0c;搭建调试环境就比较麻烦&#xff01;其实哈&#xff0c;我发现NuSphere-phped-16.0很强大&#xff0c;集成了很强大的debug功能&#xff0c;只…

ubuntu 设置开机执行脚本_ubuntu-18.04 设置开机启动脚本

ubuntu-18.04 设置开机启动脚本参阅下列链接ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本&#xff0c;通过下列简单设置后&#xff0c;可以使rc.local重新发挥作用。1、建立rc-local.service文件sudo vi /etc/systemd/system/rc-local.service2、将下列内…

Web Api单元测试写法

例如我们在Web Api项目中有个Controller public class SomeController : ApiController { public HttpResponseMessage Get() { // 一些操作 return Request.CreateResponse(HttpStatusCode.OK&#xff0c; someModel); } }如果你在单元测试中直接调用 SomeController 的Get()方…

数据挖掘深入理解和学习路径

上一篇文章中分享了数据分析的学习全景路径 其中最关键的部分就是数据挖掘&#xff0c;那什么是数据挖掘呢&#xff1f; 数据挖掘就是通过分析采集而来的数据源&#xff0c;从庞大的数据中发现规律&#xff0c;找到宝藏。 一&#xff0c;数据挖掘的基本流程 数据挖掘可分为6个步…

3G重选至4G--基于优先级

3G重选至4G--基于优先级 1. Specification 1.1 Measurementrules 是否需要开启测量 3GPP 25.304 - 5.2.6.1.2aMeasurement rules for inter-frequency and inter-RAT cell reselection when absolutepriorities are used 1.2 Evaluation/ ReselectionCriteria 对测量结…

C#_Socket网络编程实现的简单局域网内即时聊天,发送文件,抖动窗口。

C#_Socket网络编程实现的简单局域网内即时聊天&#xff0c;发送文件&#xff0c;抖动窗口。 最近接触了C#Socket网络编程&#xff0c;试着做了试试(*^__^*) 实现多个客户端和服务端互相发送消息 发送文件抖动窗口功能 服务端&#xff1a; using System; using System.Colle…

移动端大图缩放模糊_关于移动端小图标模糊问题的解决方法

前言之前给大家讲到图片和文字垂直方向不对齐的问题&#xff0c;其中举的小例子中用到了一个小图标&#xff0c;这个小图标我用的是背景图来显示&#xff1a;.del .icon{ display: inline-block; width: 20px; height: 25px; margin-right: 5px;vertical-align: middle; backgr…

T-SQL WITH 分号问题

使用with 前面有sql语句时候 运行 with tempTbale(id) as ( select ..... )select * from tempTbale 运行上面语句 提示下面错误 Incorrect syntax near the keyword with. If this statement is a common table expression, an xmlnamespaces clause or a change tracking con…

SVN 撤回(回滚)提交的代码

转&#xff1a; SVN 撤回&#xff08;回滚&#xff09;提交的代码 2016年12月20日 17:20:58 怀色 阅读数 68614 标签&#xff1a; svn svn回滚 版本回滚 更多 个人分类&#xff1a; svn 版权声明&#xff1a;本文为博主原创文章&#xff0c;未经博主允许不得转载。 https://…

LTE-怎么获取上行资源

LTE中&#xff0c;UE如果要发送上行数据(Control sig or Data)&#xff0c;需要上行pusch资源&#xff0c;如果没有被分配pusch的话&#xff0c;则需要申请。 有3种方法进行申请&#xff1a; 这3中方法对应不同的场景&#xff0c;详细逻辑如下&#xff1a;

mysql中sql语句

<数据定义语言DDL> 一. create TABLE tableName 创建表 二. alter TABLE tableName 修改表 三. drop TBALE tableName 删除表 <数据控制语言DCL> GRANT/REVOKE <数据操纵语言DML> 一. insert INTO tableName(,,,) values(,,,); 插入数据(增) 二. update tabl…

wxpython有没有可视化设计_wxPython - GUI Builder工具( GUI Builder Tools)

wxPython - GUI Builder工具( GUI Builder Tools)通过手动编码创建美观的GUI可能很乏味。 可视化GUI设计器工具总是很方便。 许多针对wxPython的GUI开发IDE都可用。 以下是其中一些 -wxFormBuilderwxDesignerwxGladeBoaConstructorgui2pywxFormBuilder是一个开源的&#xff0c;…

微信网页JSDK接口-wx.chooseImage问题

wx.chooseImage({count: 1, // 默认9sizeType: [original, compressed], // 可以指定是原图还是压缩图&#xff0c;默认二者都有sourceType: [album, camera], // 可以指定来源是相册还是相机&#xff0c;默认二者都有success: function (res) {var localIds res.localIds; //…

ARM 的几个重要特点

ARM 采用RISC指令集 ARM: Acorn RISC Machine; //Acorn: 公司的名字 它支持的指令比较简单&#xff0c;所以功耗小、价格便宜&#xff0c;特别合适移动设备。 RISC 和CISC的区别&#xff1a; 举例子&#xff0c;乘加运算&#xff0c;比如&#xff1a; ya*b c; 在CISC里面…

html文字中横线_谈PPT课件中自定义动画应用之内容控制

本案例来源于一位资深政治教师的课件应用经验。在她的朋友圈看到&#xff1a;讲解高考政治主观题课件要这样做才好&#xff0c;材料全部显示完后&#xff0c;再把一些关键字词句用彩色字标注或横线或圆圈标注&#xff0c;然后再分析归纳&#xff0c;哪些字词句是设问范围内应该…

PowerShell过滤文件中的重复内容

Get-Content -Path E:\test11\data.txt | Sort-Object | Get-Unique 源文件&#xff1a; AA0001 2014-06-30 15:27:13.073 AA0001 2014-06-30 15:27:13.073 AA0001 2014-06-30 15:27:13.073 AA0002 2014-06-30 15:27:30.607 AA0002 2014-06-30 15:28:00.467 AA0003 2014-06-30 …

pstree进程管理

功能&#xff1a;pstree命令列出当前的进程&#xff0c;以及它们的树状结构。 格式&#xff1a;pstree [选项] [pid|user] 主要选项如下&#xff1a; -a&#xff1a;显示执行程序的命令与完整参数。 -c&#xff1a;取消同名程序&#xff0c;合并显示。 -h&#xff1a;对输出结果…

LTE MIB 的发送周期

MIB在PBCH上发送&#xff0c;PBCH 采用QPSK调制。 PBCH的时频资源位置固定&#xff0c;可以参考我的博文” LTE FDD PSS/SSS/MIB时频资源位置”. 一个SFN发送一次MIB&#xff0c;接下来3个SFN重复发送同样的信息(但是以不同的扰码加扰)&#xff0c;也就是说MIB的发送周期为4…

吸顶wifi_分享 | 酒店WiFi网络的三种部署模式

酒店的无线网络&#xff0c;在酒店部署移动网络业务的时候&#xff0c;很多酒店会发现实际效果远达不到预期。酒店员工和入住用户经常会抱怨无线网络不稳定、视频无限缓冲中、经常掉线……&#xff0c;那么今天我们来了解酒店无线网络的部署。一、影响WiFI漫游的因素导致出现以…

最后一片蓝海的终极狂欢-写在Win10发布前夕

作为一名Windows8.x系统平台从业者&#xff0c;从工作伊始&#xff0c;耳边不断充斥着Windows将走向没落的言论&#xff0c;Win10今日晚些时候即将发布&#xff0c;笔者借此机会&#xff0c;说说自己的看法。 早在2012年的时候&#xff0c;IDC曾预测&#xff0c;WP系统将在2016…

错误信息输出,重定向到文件

将错误重定向到文件remove-item none 2> d:\ee.txt 将错误追加到已有文件remove-item none 2>> d:\ee.txt 将错误发送到成功输出流。如果报错后&#xff0c;代码依然继续执行&#xff0c;则Exception不会被捕获到$myerror Remove-Item "NoSuchDirectory" 2…

spark-submit --files 动态加载外部资源文件

在做spark时&#xff0c;有些时候需要加载资源文件&#xff0c;需要在driver或者worker端访问。在client模式下可以使用IO流直接读取,但是在cluster模式下却不能直接读取&#xff0c;需要如下代码&#xff1a; val is: InputStream this.getClass.getResourceAsStream(“./xxx…

LTE SIB1时频资源

1.时域资源 参考3GPP 36.331 – 5.2.1.2Scheduling The SystemInformationBlockType1 uses a fixed schedule with a periodicity of 80 msand repetitions made within80 ms. Thefirst transmission of SystemInformationBlockType1 is scheduled insubframe #5 of radio fram…

ssm框架mysql配置_ssm框架使用详解配置两个数据源

学习ssm框架已经快一年了&#xff0c;今天把这个框架总结一下。SSM 就是指 spring、SpringMVC和Mybatis。先说一下基本概念(百度上搜的)1、基本概念1.1、SpringSpring是一个开源框架&#xff0c;Spring是于2003 年兴起的一个轻量级的Java 开发框架&#xff0c;由Rod Johnson 在…

Linux下JDK环境的配置

whereis javawhich java &#xff08;java执行路径&#xff09;echo $JAVA_HOME rpm -ivh jdk-7u79-linux-x64.rpm 配置profile 转载于:https://www.cnblogs.com/xubc/p/4686748.html

org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar

通过Spring的jdbcTemplate调用Mysql的存储过程&#xff0c;出现下面的问题&#xff08;以前也使用过&#xff0c;并没有出现下面的问题&#xff0c;折腾大半天&#xff0c;郁闷&#xff09;&#xff1a;开始报下面的错误&#xff1a;[INFO ]2014-07-01 10:49:15,297 MESSAGE : …

Aras学习笔记(1)学习Aras已半年有余,也积攒一些学习笔记,今天起会陆续分享出来,有兴趣的朋友一起交流...

Aras Innovator PLM简介 美国Aras公司的产品生命周期&#xff08;PLM&#xff09;软件。Aras Innovator是微软在PLM领域唯一的一家金牌合作伙伴。是全球首款达到CMII 4星级的开放许可的企业级PLM(OPEN PLM)产品。通过软件许可&#xff08;节点&#xff09;免费&#xff0c;服务…

LTE CRS 时频资源

1. 参考 Spec 3GPP-36.211-6.10 Cell-specificReference Signal (CRS) Cell-specificreference signals are transmitted on one or several of antenna ports 0 to 3. Cell-specific reference signals are defined for Δf 15 kHzonly 2. 时频位置公式 在36.211-6.10.1.…