原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1305

字典树裸题,如下:

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
const int Max_N = ;
struct Node{
int cnt;
Node *next[];
inline void set(){
cnt = ;
for (int i = ; i < ; i++) next[i] = NULL;
}
};
struct Trie{
Node stack[Max_N], *root, *tail;
void init(){
tail = &stack[];
root = tail++;
root->set();
}
inline Node *newNode(){
Node *p = tail++;
p->set();
return p;
}
inline void insert(Node *x, char *src){
char *p = src;
while (*p != '\0'){
if (!x->next[*p - '']) x->next[*p - ''] = newNode();
x = x->next[*p - ''];
x->cnt++;
p++;
}
}
inline int query(Node *x, char *src){
char *p = src;
while (*p != '\0'){
if (!x || !x->next[*p - '']) return ;
x = x->next[*p - ''];
p++;
}
return x->cnt;
}
inline void insert(char *src){
insert(root, src);
}
inline int query(char *src){
return query(root, src);
}
}trie;
char ret[][], buf[];
int main(){
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
trie.init();
int i, n = , k = , flag = ;
while (~scanf("%s", buf)){
if ( != strcmp(buf, "")){
trie.insert(buf);
strcpy(ret[n++], buf);
} else if ( == strcmp(buf, "")){
flag = ;
for (i = ; i < n; i++){
if (trie.query(ret[i]) > ){
printf("Set %d is not immediately decodable\n", k++);
flag = ;
break;
}
}
if (!flag) printf("Set %d is immediately decodable\n", k++);
n = , flag = ;
trie.init();
}
}
return ;
}

hdu 1305 Immediate Decodability的更多相关文章

  1. hdu 1305 Immediate Decodability(字典树)

    Immediate Decodability Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  2. HDU 1305 Immediate Decodability 可直接解码吗?

    题意:一个码如果是另一个码的前缀,则 is not immediately decodable,不可直接解码,也就是给一串二进制数字给你,你不能对其解码,因解码出来可能有多种情况. 思路:将每个码按长 ...

  3. (step5.1.2)hdu 1305(Immediate Decodability——字典树)

    题目大意:输入一系列的字符串,判断这些字符串中是否存在其中的一个字符串是另外一个字符串的前缀.. 如果是,输出Set .. is not immediately decodable 否则输出Set . ...

  4. Immediate Decodability HDU - 1305(模板trie)

    求这些01串是否有一个是另一个的前缀.. 就是求次数就好了嘛...emm... 网上竟然都用指针写.... #include<cstdio> #include<iostream> ...

  5. hdu 1305 还是字典树

    #include<cstdio> #include<iostream> #include<string> #include<cstdlib> #defi ...

  6. HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配)

    HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配) Description The zoo have N cats and M dogs, toda ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  9. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

随机推荐

  1. x86_64 Ubuntu 14.04 LST安装gcc4.1.2 转载

    由于编译源码软件需要用到gcc4.1.2版本,但是本机已经安装有gcc4.8.4,下载gcc4.1.2源码编译总会出现运行找不到库文件错误,或者i386和x86_64不兼容问题,在http://ask ...

  2. socket学习笔记——并发服务器与I/O程序分割客户端

    client.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <u ...

  3. MSP430F149学习之路——捕获/比较模式

    1.捕获模式 #include <msp430x14x.h> unsigned ,last1=; unsigned ,j=; void mian(void) { WDTCTL = WDTP ...

  4. js控制台调试

    在web编程的过程中js代码出现错误,可以通过console.log()将相关信息输入到控制台进行调试. 清空控制台右击选 Clear console 菜单,或者输入 clear() 都行 控制台相关 ...

  5. mysql显示乱码问题

    在select * from table:时往往会出现上图所示乱码现象 此时,输入status,会发现: 此时只要SET NAMES utf8即可解决该问题.此时,再次输入status:   总结:S ...

  6. 二模11day2解题报告

    T1.修改文章(amend) 给出n个单词和一个长度为m的字符串,求改动多少个字符才能使字符串全由单词组成. 要说这道题还真的坑很坑超坑非常坑无敌坑--不过还是先想到了动规.毕竟要修改的前提是要组成的 ...

  7. Could not resolve this reference. Could not locate the assembly

    Rebuild Project 的时候提示找不到NewtonJson 组件,重新添加了Dll(Newtonsoft.Json.dll),依然抛错. 解决办法,将Dll(Newtonsoft.Json. ...

  8. Linux:ssh远程执行命令并自动退出

    ssh命令格式: [root@localhost ~]# ssh --helpusage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c ...

  9. fstab

    开机后,挂载windows盘失败, 进入了一个检测shell,该shell下是以只读方式挂载根分区的,要使fstab可写,要执行mount -o remount,rw / /etc/fstab文件的解 ...

  10. MFC创建对话框组件对应变量并进行设置值(VS2010)

    m_path = strFolderPath; UpdateData(FALSE);