HDU1305 Immediate Decodability(水题字典树)
巧了,昨天刚刚写了个字典树,手到擒来,233。
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: B: C: D: but this one is not:
A: B: C: D: (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 ; 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 Sample Output
Set is immediately decodable
Set is not immediately decodable
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<memory.h>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
char s[];
int note[];//是否有延伸
int c[][],cnt;//记录下一个点节点
bool flag=false;
void _add()
{
int tmp=;
for(int i=;i<strlen(s)-;i++){
if(c[tmp][s[i]-'']==) c[tmp][s[i]-'']=++cnt;
tmp=c[tmp][s[i]-''];
if(note[tmp]) flag=true;
}
if(c[tmp][s[strlen(s)-]-'']!=) flag=true;
else {
c[tmp][s[strlen(s)-]-'']=++cnt;
note[cnt]=;
}
}
int main()
{
int T=;
while(~scanf("%s",s)){
if(s[]==''){
if(!flag)printf("Set %d is immediately decodable\n",++T);
else printf("Set %d is not immediately decodable\n",++T);
flag=false;cnt=;
memset(c,,sizeof(c));
memset(note,,sizeof(note));
}
else _add();
}
return ;
}
HDU1305 Immediate Decodability(水题字典树)的更多相关文章
- HDU1671 水题字典树
#include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> #inc ...
- C#LeetCode刷题-字典树
字典树篇 # 题名 刷题 通过率 难度 208 实现 Trie (前缀树) 48.6% 中等 211 添加与搜索单词 - 数据结构设计 39.9% 中等 212 单词搜索 II 27.9% ...
- hdu1305 字典树水题
题意: 给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路: 字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- HDU1305 Immediate Decodability (字典树
Immediate Decodability An encoding of a set of symbols is said to be immediately decodable if no cod ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- CDOJ 1060 秋实大哥与快餐店 字典树 水题
题目链接 B - 秋实大哥与快餐店 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Sub ...
- bzoj1103树状数组水题
(卧槽,居然规定了修改的两点直接相连,亏我想半天) 非常水的题,用dfs序(而且不用重复,应该是直接规模为n的dfs序)+树状数组可以轻松水 收获:树状数组一遍A(没啥好骄傲的,那么简单的东西) #i ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
随机推荐
- 机器学习实战之 第10章 K-Means(K-均值)聚类算法
第 10 章 K-Means(K-均值)聚类算法 K-Means 算法 聚类是一种无监督的学习, 它将相似的对象归到一个簇中, 将不相似对象归到不同簇中.相似这一概念取决于所选择的相似度计算方法.K- ...
- grunt之connect、watch
先说下这两个插件配合的用处,简单的说,它们可以拯救你的F5.connect用于建立一个静态服务器,watch监听文件的修改并自动实时刷新浏览器的页面. 还是options走起. connect(V0. ...
- 1~N任意三个数最大的最小公倍数(Java版)
最大最小公倍数 如题 话不多说,直接上代码 public class MaxCommonMultiple{ public static void main(String[] args) { Scann ...
- 201521123075 《Java程序设计》第8周学习总结
1. 本周学习总结 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4-1) 1.1 实验总结 进行删除操作的时候最好从末尾开始删除.如果从开头开始删除,会使每个元素的对应位置发生 ...
- 201521123012 《Java程序设计》第七周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代 ...
- 201521123108《Java程序设计》第1周学习总结
本周学习总结 刚加入java的学习,我感觉很困难.但我觉得学习并不是一蹴而就.只要我多读,多看,多练,一定会取得进步.有空的时候把书本上的代码敲一敲.相信会有回报. 2.书面作业 1.为什么java程 ...
- 201521123121 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. Java流(Stream).文件(File)和IO Java.io包几乎包含了所有操作输入.输出需要的类.所有 ...
- JDBC第四篇--【数据库连接池、DbUtils框架、分页】
1.数据库连接池 什么是数据库连接池 简单来说:数据库连接池就是提供连接的. 为什么我们要使用数据库连接池 数据库的连接的建立和关闭是非常消耗资源的 频繁地打开.关闭连接造成系统性能低下 编写连接池 ...
- 纳税服务系统【用户模块之使用POI导入excel、导出excel】
前言 再次回到我们的用户模块上,我们发现还有两个功能没有完成: 对于将网页中的数据导入或导出到excel文件中,我们是完全没有学习过的.但是呢,在Java中操作excel是相对常用的,因此也有组件供我 ...
- mybatis-mapper文件介绍
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...