poj-1056-IMMEDIATE DECODABILITY(字典)
Description
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
Output
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
题目大意:
就是输多组0 1数据,任意一组数据不能成为另一种的前缀;
一组符号的编码是立即可解码的如果没有前缀的代码一个符号代码的另一个象征。我们将假定这个问题,所有的二进制代码,没有两个编码在一组编码是相同的,每个代码至少有一个,不超过十位,每组至少有两个编码和不超过8个。
例子:假设一个字母,符号{ A,B,C,D }
下面的代码是立即可解码
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{ string str[10];
int i=0; int y=1,w=0;
while(cin>>str[i])
{ if(str[i]=="9")
{
i=0;
w++;
if(y==1)cout<<"Set "<<w<<" is immediately decodable"<<endl;
else cout<<"Set "<<w<<" is not immediately decodable"<<endl;
y=1; } int len=str[i].length(); //新输入字符长度
for(int j=0;j<i;j++) //没输一组数据都与原来的进行比较
{
int t=0;
int len1=str[j].length(); //已存入数据的字符长度
for(int k=0;k<len&&k<len1;k++) //保证以短的字符串长度为比较界限
{
if(str[i][k]==str[j][k])
{ t++;
} }
if(t==min(len,len1)){y=0;break;} //若等式成立则说明此字符串必为某字符串前缀 }
i++;
} return 0; }
poj-1056-IMMEDIATE DECODABILITY(字典)的更多相关文章
- poj 1056 IMMEDIATE DECODABILITY 字典树
题目链接:http://poj.org/problem?id=1056 思路: 字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变 ...
- poj 1056 IMMEDIATE DECODABILITY(KMP)
题目链接:http://poj.org/problem?id=1056 思路分析:检测某字符串是否为另一字符串的前缀,数据很弱,可以使用暴力解法.这里为了练习KMP算法使用了KMP算法. 代码如下: ...
- POJ 1056 IMMEDIATE DECODABILITY
IMMEDIATE DECODABILITY Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9630 Accepted: ...
- POJ 1056 IMMEDIATE DECODABILITY 【Trie树】
<题目链接> 题目大意:给你几段只包含0,1的序列,判断这几段序列中,是否存在至少一段序列是另一段序列的前缀. 解题分析: Trie树水题,只需要在每次插入字符串,并且在Trie树上创建节 ...
- POJ 1056 IMMEDIATE DECODABILITY Trie 字符串前缀查找
POJ1056 给定若干个字符串的集合 判断每个集合中是否有某个字符串是其他某个字符串的前缀 (哈夫曼编码有这个要求) 简单的过一遍Trie就可以了 #include<iostream> ...
- POJ 2001 Shortest Prefixes(字典树)
题目地址:POJ 2001 考察的字典树,利用的是建树时将每个点仅仅要走过就累加.最后从根节点開始遍历,当遍历到仅仅有1次走过的时候,就说明这个地方是最短的独立前缀.然后记录下长度,输出就可以. 代码 ...
- 【POJ】1056 IMMEDIATE DECODABILITY
字典树水题. #include <cstdio> #include <cstring> #include <cstdlib> typedef struct Trie ...
- hdu 1305 Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- poj 1204 Word Puzzles(字典树)
题目链接:http://poj.org/problem?id=1204 思路分析:由于题目数据较弱,使用暴力搜索:对于所有查找的单词建立一棵字典树,在图中的每个坐标,往8个方向搜索查找即可: 需要注意 ...
- POJ 2408 - Anagram Groups - [字典树]
题目链接:http://poj.org/problem?id=2408 World-renowned Prof. A. N. Agram's current research deals with l ...
随机推荐
- linux ftp及C/S服务架构
乱码转换工具使用convmv软件:windows中文字符编码为GB2312 linux中文字符编码为utf-8选项:-f:源文件中中文字符编码-t:转换成字符编码-r:代表递归--notest:不测试 ...
- spring-java项目中连接redis数据库
最近由于项目需要,要从redis数据库中查询一些数据,还没有了解过redis,只好硬着头皮上阵,记录一下连接过程: 1.需要导入两个jar包:jedis.jar,spring-data-redis.j ...
- mysql常用基础操作语法(八)~~多表查询合并结果和内连接查询【命令行模式】
1.使用union和union all合并两个查询结果:select 字段名 from tablename1 union select 字段名 from tablename2: 注意这个操作必须保证两 ...
- stl string 容器的使用
string 是基本的字符串序列容器,对应数据结构中的串,和vector<char>也类似,但功能更多 string 容器的使用 1,string 的构造函数是. string() 2,s ...
- VxWorks6.6 pcPentium BSP 使用说明(一):基本概念
"VxWorks6.6 BSP 使用说明"将发布pcPentium和idp945两个系列的BSP的使用说明.每个系列约5篇文章.之后还将发布由这两个官方提供的BSP的实战移植方法. ...
- Linux显示登录Shell信息
Linux显示登录Shell信息 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ finger -p Login Name Tty Idle Login Tim ...
- java.lang.Exception: Socket bind failed
1.错误描述 严重: Failed to initialize end point associated with ProtocolHandler ["http-apr-8080" ...
- 移动端web开发安卓和ios客户端在时间转换上的差异性问题
作为一名移动前端开发的人员,平时遇到的兼容性问题不在少数.那么,今天就来说一下最近遇到的一个小坑(关于Android和ios在时间转换上的差异性问题)话不多说,直接上重点. 最近接到了一个需求,很简单 ...
- myeclipse 打开jsp文件出错
第一步:找到MyEclipse的安装路径:第二步:删除掉MyEclipse\configuration下名为:org.eclipse.update的文件夹:第三步:产出之后重启myeclipse,在打 ...
- RobotFramework下HttpLibrary库其它关键字
关键字 使用描述 DELETE 向服务器端发送http delete请求,该请求接收一个参数[ url ],请求的方式和post请求非常类似,示例: DELETE /_utils/config.htm ...