原题链接: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. java基础回顾(五)——Stack、Heap

    栈(stack):是简单的数据结构,但在计算机中使用广泛.栈最显著的特征是:LIFO(Last In, First Out,后进先出).比如我们往箱子里面放衣服,先放入的在最下方,只有拿出后来放入的才 ...

  2. 智能指针(二):shared_ptr实现原理

    前面讲到auto_ptr有个很大的缺陷就是所有权的转移,就是一个对象的内存块只能被一个智能指针对象所拥有.但我们有些时候希望共用那个内存块.于是C++ 11标准中有了shared_ptr这样的智能指针 ...

  3. sass sublime text 2 gulp ionic

    sass 安装1.全局安装 sass 我的Mac 所以不用再安装Ruby ,直接在终端输入 gem install sass 然后在终端中输入 sass -v 出现 Sass 3.4.8 (selec ...

  4. 拿搬东西来解释udp tcpip bio nio aio aio异步

     [群主]雷欧纳德简单理解 tcpip是有通信确认的面对面通信   有打招呼的过程  有建立通道的过程 有保持通道的确认    有具体传输udp是看到对面的人好像在对面等你 就往对面扔东西[群主]雷欧 ...

  5. ios开发之OC基础-oc小程序

    本系列的文章主要来自于个人在学习前锋教育-欧阳坚老师的iOS开发教程之OC语言教学视频所做的笔记,边看视频,边记录课程知识点.建议大家先过一遍视频,在看视频的过程中记录知识点关键字,把把握重点,然后再 ...

  6. js获得浏览器的尺寸

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  7. ajax 方法解密

    1:GET访问 浏览器 认为 是等幂的就是 一个相同的URL 只有一个结果[相同是指 整个URL字符串完全匹配]所以 第二次访问的时候 如果 URL字符串没变化 浏览器是 直接拿出了第一次访问的结果 ...

  8. angular.extend(dst, src)对象拓展

    angular.extend(dst, src) 作用:对象的拓展 参数:  dst:拓展的对象 src:源对象 返回值:拓展的对象 var dst = {name: 'xxx', country: ...

  9. Linux下对于inode的理解

    0x01 什么是inode 文件存储在硬盘上,硬盘的最小存储单位叫做“扇区”(Sector),每个扇区储存512字节: 操作系统读取硬盘时,不会一个个扇区地读取,这样效率低,而是一次性连续读取多个扇区 ...

  10. Javascrpt

    HTML HTML概述: HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他 ...