巧了,昨天刚刚写了个字典树,手到擒来,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(水题字典树)的更多相关文章

  1. HDU1671 水题字典树

    #include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> #inc ...

  2. C#LeetCode刷题-字典树

    字典树篇 # 题名 刷题 通过率 难度 208 实现 Trie (前缀树)   48.6% 中等 211 添加与搜索单词 - 数据结构设计   39.9% 中等 212 单词搜索 II   27.9% ...

  3. hdu1305 字典树水题

    题意:      给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路:       字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...

  4. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  5. HDU1305 Immediate Decodability (字典树

    Immediate Decodability An encoding of a set of symbols is said to be immediately decodable if no cod ...

  6. HDU 1247 - Hat’s Words - [字典树水题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...

  7. CDOJ 1060 秋实大哥与快餐店 字典树 水题

    题目链接 B - 秋实大哥与快餐店 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Sub ...

  8. bzoj1103树状数组水题

    (卧槽,居然规定了修改的两点直接相连,亏我想半天) 非常水的题,用dfs序(而且不用重复,应该是直接规模为n的dfs序)+树状数组可以轻松水 收获:树状数组一遍A(没啥好骄傲的,那么简单的东西) #i ...

  9. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

随机推荐

  1. JVM中锁优化,偏向锁、自旋锁、锁消除、锁膨胀

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt364 本文将简单介绍HotSpot虚拟机中用到的锁优化技术. 自旋锁 互斥同 ...

  2. hdu 3549最大流Ford-Fulkerson算法

    Ford-Fulkerson算法 戳戳http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html Ford-Fulkerson方法依 ...

  3. [js高手之路]Vue2.0基于vue-cli+webpack同级组件之间的通信教程

    我们接着上文继续,本文我们讲解兄弟组件的通信,项目结构还是跟上文一样. 在src/assets目录下建立文件EventHandler.js,该文件的作用在于给同级组件之间传递事件 EventHandl ...

  4. JTemplates + $.Ajax

    上篇基础使用后: +AJAX 只需要改列名即可 :<script type="text/template" id="foreach">   里的循环 ...

  5. FileInputStream 小Demo

    要求:设计如下界面  文本框里面可以输入的路径和文件名  单机按钮可以读取在 指定的文件  并把文件内容显示到一个文本域里面来 代码: /** * */ package com.niit.homewo ...

  6. 201521123022 《Java程序设计》第三周学习总结

    1.本周学习总结 2.书面作业 Q1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; pu ...

  7. 201521123013 《Java程序设计》第2周学习总结

    1. 本章学习总结 1.final声明,一旦赋值不能被改变.移位运算符的应用,负数右移高位补"1",正数右移高位补"1".利用移位运算,按位与运算可以方便得出整 ...

  8. 201521123010 《Java程序设计》第10周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 2. 书面作业 本次PTA作业题集异常.多线程 ①finally 题目4-2 1.1 截图你的提交结果(出现 ...

  9. 201521123103 《Java学习笔记》 第十一周学习总结

    一.本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 二.书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1. ...

  10. LINUX - awk命令之NF和$NF区别 (转)

    NF和$NF 区别问答:(转)1.awk中$NF是什么意思?#pwd/usr/local/etc~# echo $PWD | awk -F/ '{print $NF}'etcNF代表:浏览记录的域的个 ...