#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. C#与android连接 SimpleWifi

    有时候 Read时会返回0长度 ----- 当连续2次每读到数据时,建议发个心跳信息,然后单片机给个回复 C# using System; using System.Collections.Gener ...

  2. UVa 11491 Erasing and Winning (贪心,单调队列或暴力)

    题意:给一个数字(开头非0),拿掉其中的d个数字,使剩下的数字最大(前后顺序不能变). 析:拿掉d个数字,还剩下n-d个数字.相当于从n个数字中按先后顺序选出n-d个数字使组成的数字最大,当然采用窗口 ...

  3. SPSS-单因素方差分析(ANOVA) 案例解析

    继续以上一期的样本为例,雌性老鼠和雄性老鼠,在注射毒素后,经过一段时间,观察老鼠死亡和存活情况. 研究的问题是:老鼠在注射毒液后,死亡和存活情况,会不会跟性别有关? 样本数据如下所示: (a代表雄性老 ...

  4. JavaScript面向对象编程[转]

    JavaScript面向对象编程 命名空间 命名空间是一个容器,它允许开发人员在一个独特的,特定于应用程序的名称下捆绑所有的功能. 在JavaScript中,命名空间只是另一个包含方法,属性,对象的对 ...

  5. 基于MATLAB的RGB转YCBCR色彩空间转换

    使用MATLAB进行图片的处理十分方便,看它的名字就知道了,矩阵实验室(matrix laboratory).一副图片的像素数据可以看成是一个二维数组一个大矩阵,MTABLAB就是为矩阵运算而生. M ...

  6. springmvc elf8848

    刚开始觉得孔浩讲得好,之后觉得开涛讲得好,现在觉得elf8848讲得好.其实只是自己学习的各个阶段 孔浩:环境搭建,做了个基础的CRUD 开涛:讲了Controller(不该看),注解,数据绑定,请求 ...

  7. Citrus Engine简单Demo

    Citrus Engine是一个的开源flash平台(platform,也可以说是卷轴类)游戏引擎,它基于Starling Framework添加了各种物理引擎,3D引擎,动画引擎. Citrus实现 ...

  8. Ansible基本命令

    Ansible安装完成之后就自带很多命令,其中较常用的有7个: ansible ansible-doc ansible-galaxy ansible-init ansible-playbook ans ...

  9. [redis]Redis Transaction

    https://github.com/phpredis/phpredis#transactions Transactions multi, exec, discard - Enter and exit ...

  10. TempDB--临时表的缓存

    --========================================================================== 在博客园看到一篇文章<SQLServer ...