Immediate Decodability(字典树)
Immediate Decodability
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2248 Accepted Submission(s):
1168
点我
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)
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).
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.
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define max 2
typedef struct TrieNode
{
int ncount;
struct TrieNode *next[max];
}TrieNode;
TrieNode* createTrieNode()
{
TrieNode* temp=new TrieNode;
temp->ncount=;
for(int i=;i<max;i++)
temp->next[i]=NULL;
return temp;
}
void insertTrie(TrieNode* proot,char* str)
{
TrieNode *temp=proot;
for(int i=;str[i];i++)
{
int t=str[i]-'';
if(temp->next[t]==NULL)
temp->next[t]=createTrieNode();
temp=temp->next[t];
temp->ncount++;
}
}
int searchTrie(TrieNode* p,char *str)
{
for(int i=;str[i];i++)
{
int t=str[i]-'';
p=p->next[t];
if(!p)
return ;
}
return p->ncount;
}
int main()
{
char a[][];
int i=,k=;
TrieNode* root=createTrieNode();
while(gets(a[i]))
{
int count=;
while(a[i][]!='')
{
insertTrie(root,a[i]);
i++;
gets(a[i]);
}
count=i;
for(i=;i<count;i++)
{
if(searchTrie(root,a[i])!=)
{
cout<<"Set "<<k++<<" is not immediately decodable"<<endl;
break;
}
}
if(i==count)
cout<<"Set "<<k++<<" is immediately decodable"<<endl;
i=;
}
}
Immediate Decodability(字典树)的更多相关文章
- hdu 1305 Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- (step5.1.2)hdu 1305(Immediate Decodability——字典树)
题目大意:输入一系列的字符串,判断这些字符串中是否存在其中的一个字符串是另外一个字符串的前缀.. 如果是,输出Set .. is not immediately decodable 否则输出Set . ...
- poj 1056 IMMEDIATE DECODABILITY 字典树
题目链接:http://poj.org/problem?id=1056 思路: 字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变 ...
- hdu1305Immediate Decodability(字典树)
这题看是否 这题能A是侥幸,解决的办法是先存一下输入的字符串,进行排序. Problem Description An encoding of a set of symbols is said to ...
- HDU1305 Immediate Decodability (字典树
Immediate Decodability An encoding of a set of symbols is said to be immediately decodable if no cod ...
- HDU1305 Immediate Decodability(水题字典树)
巧了,昨天刚刚写了个字典树,手到擒来,233. Problem Description An encoding of a set of symbols is said to be immediatel ...
- 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)
前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...
随机推荐
- 关于thinkphp中Hook钩子的解析
在tp框架下的Library/Think 下有一个Hook类,这个是用来以插件形式来实例化类并且执行方法的 static private $tags = array(); 这里有一个 ...
- php过滤iphone的emoji表情
public static function removeEmoji($text) { $clean_text = ""; // Match Emoticons $regexEmo ...
- Web程序工作原理
1.Web程序工作原理 (1)Web一词的含义 Network:[计算机]电脑网络,网 Web:[计算机]万维网(World Wide Web),互联网(Internet) Web程序,顾名思义,即工 ...
- ccf练习---节日
问题描述 有一类节日的日期并不是固定的,而是以“a月的第b个星期c”的形式定下来的,比如说母亲节就定为每年的五月的第二个星期日. 现在,给你a,b,c和y1, y2(1850 ≤ y1, y2 ≤ 2 ...
- BZOJ 1065 奥运物流
http://www.lydsy.com/JudgeOnline/problem.php?id=1065 思路:由于n个点,有n条边,因此由根就会引出一个环,我们枚举环的长度,在那个长度断开,我们假设 ...
- 微软的OneDrive研究~
Dropbox 很好,唯一觉得不爽的是只能同步指定的目录.不过被墙之后就不那么方便了,所以改用微软的 Live Mesh,缺点是支持的设备少(仅 PC 和 Mac). https://technet. ...
- Linux学习,在线版
考虑加入Linux教派,最初被Linux吸引是看了<Unix编程艺术>,虽然里面的个别非常教条,极端.但是里面大部分的设计思想我还是认同的. 下面是我整理的一些Linux资料,其实我打算折 ...
- UESTC_Tournament CDOJ 124
A sports company is planning to advertise in a tournament. It is a single round-robin tournament, th ...
- ubuntu下集群设置静态ip
hadoop集群时,需要固定集群内计算机相互通信之间的ip地址,但是每次进行网络连接后,ip地址都是变换的,我们希望设置一个用于集群内通信的静态ip,即使重启电脑也不会变化,同样希望能够正常的访问互联 ...
- Multiple outputs from T4 made easy – revisited » DamienG
Multiple outputs from T4 made easy – revisited » DamienG Multiple outputs from T4 made easy – revisi ...