#include <iostream>
#include <string>
#define MAXN 50
using namespace std; struct node
{
node * l;
node * r;
bool boo;
node()
{
l = NULL;
r = NULL;
boo = false;
}
}; bool ans; int _index; node res[*MAXN+]; node * insert(node * root,string s,int index,int len)
{
if(s[index] == '')
{
if(root->l == NULL)
{
root->l = &res[_index ++];
root->l->boo = false;
root->l->l = root->l->r = NULL;
if(index == len-)
{
root->l->boo = true;
return root;
}
}
else
{
if(index == len-)
{
ans = false;
return root;
}
if(root->l->boo == true)
{
ans = false;
return root;
}
} root->l = insert(root->l,s,index+,len);
return root;
}
else
{
if(root->r == NULL)
{
root->r = &res[_index ++];
root->r->boo = false;
root->r->l = root->r->r = NULL;
if(index == len-)
{
root->r->boo = true;
return root;
}
}
else
{
if(index == len-)
{
ans = false;
return root;
}
if(root->r->boo == true)
{
ans = false;
return root;
}
}
root->r = insert(root->r,s,index+,len);
return root;
}
} int main()
{
//freopen("acm.acm","r",stdin);
string s;
int time = ;
while(cin>>s)
{
_index = ;
ans = true;
node * root = &res[_index ++];
root->boo = false;
root->l = root->r = NULL;
if(ans)
{
root = insert(root,s,,s.length());
}
while(cin>>s)
{
if(s == "")
{
break;
}
if(ans)
{
root = insert(root,s,,s.length());
}
}
cout<<"Set "<<++ time;
if(ans == false)
{
cout<<" is not immediately decodable"<<endl;
}
else
{
cout<<" is immediately decodable"<<endl;
}
}
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 1056的更多相关文章

  1. poj 1056 IMMEDIATE DECODABILITY(KMP)

    题目链接:http://poj.org/problem?id=1056 思路分析:检测某字符串是否为另一字符串的前缀,数据很弱,可以使用暴力解法.这里为了练习KMP算法使用了KMP算法. 代码如下: ...

  2. poj 1056 IMMEDIATE DECODABILITY 字典树

    题目链接:http://poj.org/problem?id=1056 思路: 字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变 ...

  3. POJ 1056 IMMEDIATE DECODABILITY 【Trie树】

    <题目链接> 题目大意:给你几段只包含0,1的序列,判断这几段序列中,是否存在至少一段序列是另一段序列的前缀. 解题分析: Trie树水题,只需要在每次插入字符串,并且在Trie树上创建节 ...

  4. POJ 1056 IMMEDIATE DECODABILITY

    IMMEDIATE DECODABILITY Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9630   Accepted: ...

  5. POJ 1056 IMMEDIATE DECODABILITY Trie 字符串前缀查找

    POJ1056 给定若干个字符串的集合 判断每个集合中是否有某个字符串是其他某个字符串的前缀 (哈夫曼编码有这个要求) 简单的过一遍Trie就可以了 #include<iostream> ...

  6. 字典树trie的学习与练习题

    博客详解: http://www.cnblogs.com/huangxincheng/archive/2012/11/25/2788268.html http://eriol.iteye.com/bl ...

  7. 蓝书2.3 Trie字典树

    T1 IMMEDIATE DECODABILITY poj 1056 题目大意: 一些数字串 求是否存在一个串是另一个串的前缀 思路: 对于所有串经过的点权+1 如果一个点的end被访问过或经过一个被 ...

  8. 【POJ】1056 IMMEDIATE DECODABILITY

    字典树水题. #include <cstdio> #include <cstring> #include <cstdlib> typedef struct Trie ...

  9. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

随机推荐

  1. sklearn中的分词函数countVectorizer()的改动--保留长度为1的字符串

    1简述问题 使用countVectorizer()将文本向量化时发现,文本中长度唯一的字符串会被自动过滤掉,这对于我在做的情感分析来讲,一些表较重要的表达情感倾向的词汇被过滤掉,比如文本'没用的东西, ...

  2. 2018.10.20 bzoj2748: [HAOI2012]音量调节(背包)

    传送门 这题是不是太sbsbsb了一点. 难度直逼普及-. 直接背包判存在性就行了. 代码: #include<bits/stdc++.h> using namespace std; bo ...

  3. 2018.09.24 bzoj1816: [Cqoi2010]扑克牌(二分答案)

    传送门 简单二分答案. 我们二分最终有k个牌堆. 这样joker被选择的张数≤min(k,m)\le min(k,m)≤min(k,m) 并且joker需要被选择的张数应该是∑i−1nmax(0,k− ...

  4. 2018.07.23 洛谷P4513 小白逛公园(线段树)

    传送门 线段树常规操作了解一下. 单点修改维护区间最大连续和. 对于一个区间,维护区间从左端点开始的连续最大和,从右端点开始的连续最大和,整个区间最大和,区间和. 代码如下: #include< ...

  5. yum基本操作(转)

    原文地址:http://www.cnblogs.com/chuncn/archive/2010/10/17/1853915.html yum(全称为 Yellow dog Updater, Modif ...

  6. spring boot使用java读取配置文件,DateSource测试,BomCP测试,AnnotationConfigApplicationContext的DataSource注入

    一.配置注解读取配置文件         (1)@PropertySource可以指定读取的配置文件,通过@Value注解获取值   实例:           @PropertySource(val ...

  7. IntelliJ IDEA 2017版 编译器使用学习笔记(二) (图文详尽版);IDE快捷键使用

    补充介绍IntellJ 介绍主菜单功能及相关用途: File -------------> 对文件进行操作 Edit ------------> 对文本进行操作 View -------- ...

  8. Field '***********' doesn't have a default value

    今天做配置文件一直报这个错误: 原因是主键是integer类型,没有设置自增模式,所以会出现这个问题,是表的结构问题.更改用navicat

  9. HDU 3361 ASCII (水题,不说什么了)

    题意:给你n个十进制数,让你输出相应的ASCII. 析:无,没说的,直接输出就好了. 代码如下: #include <iostream> #include <cstdio> # ...

  10. Windows环境下的安装gcc

    Windows具有良好的界面和丰富的工具,所以目前linux开发的流程是,windows下完成编码工作,linux上实现编译工作. 为了提高工作效率,有必要在windows环境下搭建一套gcc,gdb ...