hdu1305Immediate Decodability(字典树)
这题看是否
这题能A是侥幸,解决的办法是先存一下输入的字符串,进行排序。
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)
10
0010
0000
9
01
10
010
0000
9
Set 2 is not immediately decodable
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
typedef struct Node
{
struct Node *next[2];
int flag;
}Node,*Tree;
int flag1;
void Creat(Tree &T)
{
T=(Node *)malloc(sizeof(Node));
T->flag=0;
for(int i=0;i<2;i++)
T->next[i]=NULL;
}
void insert(Tree &T,char *s)
{
Tree p=T;
int t;
int l=strlen(s);
for(int i=0;i<l;i++)
{
t=s[i]-'0';
if(p->next[t]==NULL)
Creat(p->next[t]);
p=p->next[t];
if(p->flag>0)
flag1=0;
}
p->flag++;
}
void D(Tree p)
{
for(int i=0;i<2;i++)
{
if(p->next[i]!=NULL)
D(p->next[i]);
}
free(p);
}
int main()
{
char a[30];
int kk=0;
Tree T;
while(scanf("%s%*c",a)!=EOF)
{
Creat(T);
kk++;
flag1=1;
insert(T,a);
while(scanf("%s",a)!=EOF)
{
if(strcmp(a,"9")==0)
break;
insert(T,a);
}
if(flag1)
printf("Set %d is immediately decodable\n",kk);
else printf("Set %d is not immediately decodable\n",kk);
D(T);
}
return 0;
}
hdu1305Immediate 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类型的变 ...
- Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- 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轮游戏,最后胜利的人是谁. 思路: 很 ...
随机推荐
- linux c++环境
set expandtab set autoindent set smartindent
- 【Spring源码分析系列】bean的加载
前言 以 BeanFactory bf = new XmlBeanFactory(new ClassPathResource("beans.xml"));为例查看bean的加载过 ...
- 修改JS文件不能及时在页面中体现,需重启浏览器?
对JS文件做个小小的改动,哪怕是加一句简单的ALERT语句,都要重启浏览器才能看到.你有这样的烦恼吗?怎样不用重启浏览器就能及时体现JS的变化呢? 对浏览器(IE)做如下设置即可:1.点击 工具栏 - ...
- jQuery事件处理(四)
看了几天,决定整理一下jQuery事件处理的整体设计思路 1.通过add方法给选中的元素注册事件处理程序(通过缓存系统将事件储存到cache,而不是绑定到元素上) a.在存储之前,会为事件处理程序增加 ...
- 浏览器 User Agent字符串列表
http://www.73207.com/useragent/ http://www.73207.com/useragent/pages/internet-2520explorer/index.htm ...
- gerrit_bash_commands.sh
https://github.com/tomwys/gerrit-bash-commands gerrit_bash_commands.sh # Author: Tomasz Wysocki < ...
- spring应用中多次读取http post方法中的流(附源码)
一.问题简述 先说下为啥有这个需求,在基于spring的web应用中,一般会在controller层获取http方法body中的数据. 方式1: 比如http请求的content-type为appli ...
- 为Gem 添加环境设定
如果在测试环境中 gem "rspec", :group => :test 当多个gem的时候 group :test do gem "webrat" g ...
- Unity3D笔记 英保通十 射线碰撞器检测
射线碰撞检测可以用来检测方向和距离: 通过Physics.RayCast光线投射来实现:常用于射击利用发射的射线来判断.还有对战中刀剑交战中.. 一.要涉及到RayCast和RayCastHit 1. ...
- Xcode - 打开工程,提示No Scheme解决
错误提示,如图: 解决思路: