POJ 1056 IMMEDIATE DECODABILITY
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9630 | Accepted: 4555 |
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
题目大意:给定一段编码,每段编码以“9”结束,判断是否有一个编码是另一个编码的前缀。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std; typedef struct node
{
int n;
node *next[];
node()
{
for (int i = ; i < ; i++)
{
next[i] = NULL;
}
n = ;
}
}TreeNode; void Insert(char str[], TreeNode *pHead)
{
TreeNode *p = pHead;
int nLen = strlen(str);
for (int i = ; i < nLen; i++)
{
if (p->next[str[i] - ''] == NULL)
{
p->next[str[i] - ''] = new TreeNode;
}
else
{
p->next[str[i] - '']->n++;
}
p = p->next[str[i] - ''];
}
} int Search(char str[], TreeNode *pHead)
{
int nLen = strlen(str);
TreeNode *p = pHead;
bool bfind = false;
for (int i = ; i < nLen; i++)
{
p = p->next[str[i] - ''];
}
return p->n;
} void Delete(TreeNode *pHead)
{
for (int i = ; i < ; i++)
{
if (pHead != NULL)
{
pHead = pHead->next[i];
Delete(pHead);
}
}
delete pHead;
} int main()
{
char str[][];
int nCase = ;
int n = -;
TreeNode *pHead = new TreeNode;
int flag = ;
while(scanf("%s", str[++n]) != EOF)
{
if (str[n][] == '')
{
++nCase;
for (int i = ; i < n ; i++)
{
if (Search(str[i], pHead) > )
{
printf("Set %d is not immediately decodable\n", nCase);
break;
}
if (i == n - )
{
printf("Set %d is immediately decodable\n", nCase);
}
}
Delete(pHead);
pHead = new TreeNode;
n = -;
}
else
{
Insert(str[n], pHead);
}
}
return ;
}
POJ 1056 IMMEDIATE DECODABILITY的更多相关文章
- poj 1056 IMMEDIATE DECODABILITY(KMP)
题目链接:http://poj.org/problem?id=1056 思路分析:检测某字符串是否为另一字符串的前缀,数据很弱,可以使用暴力解法.这里为了练习KMP算法使用了KMP算法. 代码如下: ...
- poj 1056 IMMEDIATE DECODABILITY 字典树
题目链接:http://poj.org/problem?id=1056 思路: 字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变 ...
- POJ 1056 IMMEDIATE DECODABILITY 【Trie树】
<题目链接> 题目大意:给你几段只包含0,1的序列,判断这几段序列中,是否存在至少一段序列是另一段序列的前缀. 解题分析: Trie树水题,只需要在每次插入字符串,并且在Trie树上创建节 ...
- POJ 1056 IMMEDIATE DECODABILITY Trie 字符串前缀查找
POJ1056 给定若干个字符串的集合 判断每个集合中是否有某个字符串是其他某个字符串的前缀 (哈夫曼编码有这个要求) 简单的过一遍Trie就可以了 #include<iostream> ...
- 【POJ】1056 IMMEDIATE DECODABILITY
字典树水题. #include <cstdio> #include <cstring> #include <cstdlib> typedef struct Trie ...
- 1056 IMMEDIATE DECODABILITY
题目链接: http://poj.org/problem?id=1056 题意: 给定编码集, 判断它是否为可解码(没有任何一个编码是其他编码的前缀). 分析: 简单题目, 遍历一遍即可, 只需判断两 ...
- POJ 1056
#include <iostream> #include <string> #define MAXN 50 using namespace std; struct node { ...
- POJ题目排序的Java程序
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...
- 蓝书2.3 Trie字典树
T1 IMMEDIATE DECODABILITY poj 1056 题目大意: 一些数字串 求是否存在一个串是另一个串的前缀 思路: 对于所有串经过的点权+1 如果一个点的end被访问过或经过一个被 ...
随机推荐
- java mongodb-crud
本篇文章主要介绍了mongodb对应java的常用增删改查的api,以及和spring集成后mongoTemplate的常用方法使用,废话不多说,直接上代码: 1.首先上需要用到的两个实体类User和 ...
- tar打包压缩命令
1. tar命令 用法: tar [选项...] [FILE]... GNU ‘tar’将许多文件一起保存至一个单独的磁带或磁盘归档,并能从归档中单独还原所需文件. 示例 tar -cf archiv ...
- Vue实例的4个常用选项
1.过滤器 filters:在不改变的data的情况下输出前端页面需要的格式数据.例如将小数过滤为整数等.filters是一个对象,里边定义一个function方法,function传入一个参数,fu ...
- Hibernate三种批量处理数据
概念:批量处理数据是指在一个事务场景中处理大量数据. 在应用程序中难以避免进行批量操作,Hibernate提供了以下方式进行批量处理数据: (1)使用HQL进行批量操作 数据库层面 execute ...
- ycsb安装和使用介绍
nosql性能测试工具ycsb0.1的使用 使用文档参考地址:https://www.cnblogs.com/SailorXiao/p/5808828.html ycsb地址:https://gith ...
- Grace Huang 2017/1/11
原文 This actress becomes each character she plays Grace Huang has no interested in doing same thing y ...
- NBUT 1114 Alice's Puppets(排序统计,水)
题意:给一棵人名树,按层输出,同层则按名字的字典序输出. 思路:首先对每个人名做索引,确定其在哪一层,按层装进一个set,再按层输出就自动排好序了. #include <bits/stdc++. ...
- MFC技术积累——基于MFC对话框类的那些事儿
1. 创建对话框类 (1)打开VC++6.0环境,点击:文件→新建: (2)在弹出的新建对话框中选择:工程→MFC AppWizard (exe)→输入工程名称(例如:功能调试)→工程保存路径名→确定 ...
- Clusterware 和 RAC 中的域名解析的配置校验和检查 (文档 ID 1945838.1)
适用于: Oracle Database - Enterprise Edition - 版本 10.1.0.2 到 12.1.0.1 [发行版 10.1 到 12.1]Oracle Database ...
- C++判断两个double类型双精度浮点数是否同号
看到的一种整数的方法 != y < ) 由此, double x,y; == fabs( ) { } 目前想到的比较合适判断方法. 此外这里还有一种强制转换类型求符号位的方法. /** * Ge ...