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轮游戏,最后胜利的人是谁. 思路: 很 ...
随机推荐
- Stratix内嵌存储器测试报告
Stratix和Stratix GX系列器件内嵌TriMatrix存储块包括512-bit M512块.4-Kbit M4K块及512-Kbit M-RAM块.TriMatrix存储结构可对 ...
- WP8.1学习系列(第十六章)——交互UX之命令模式
命令模式 在本文中 命令类型 命令放置 相关主题 你可以在应用商店应用的几个曲面中放置命令和控件,包括应用画布.弹出窗口.对话框和应用栏.在正确的时间选择合适的曲面可能就是易于使用的应用和很难使用 ...
- 【cs229-Lecture4】GLMS:选定指数分布族,如何用它来推导出GLM?
在Lecture4中有3部分内容: Newton’s method 牛顿方法 Exceponential Family 指数分布族 Generalized Linear M ...
- 架设FTP Server-Windows Server 2012
架设FTP Server-Windows Server 2012 https://jingyan.baidu.com/article/03b2f78c75b9b65ea237ae84.html 在 ...
- Javascript常见性能优化
俗话说,时间就是生命,时间就是金钱,时间就是一切,人人都不想把时间白白浪费,一个网站,最重要的就是体验,而网站好不好最直观的感受就是这个网站打开速度快不快,卡不卡. 当打开一个购物网站卡出翔,慢的要死 ...
- 深入学习Make命令和Makefile(上)
https://www.zybuluo.com/lishuhuakai/note/209302 深入学习Make命令和Makefile(上) make是Linux下的一款程序自动维护工具,配合make ...
- git查看指令
打开git bash 1,查看自己之前是否生成过ssh密钥 $ ls .ssh 如果存在这个id_rsa.pub这个文件的话表示已经生成了 2,查看用户名和邮箱 $ git config --glob ...
- mrtg 和 rrdtools
mrtg可能很多人都用过,但那已经是n久以前的事了,现在在国内很多IDC,ISP都还用这个,因为我们这有个Linux科学家,在Linux工作n 久,我也就沾点光,学了不少东西,现在给大家介绍一个rrd ...
- Minix中的字符判定ctype.c
minix中关于如何判定一个字符的类型,如大写.小写.数字…… 如果采用传统的方法,如判断一个字母大写的方法: if(c>='A' && c<'Z') return tru ...
- cadence allegro 封装焊盘编号修改 (引脚编号修改)
1. 打开dra文件在find里面 off all 然后只点击text 2.点击需要更改的焊盘 3.菜单栏edit - text 4.弹出窗口修改即可 注意: 按照网上的其他操作并没有执行步骤1操作 ...