hdu 1305 Immediate Decodability
原题链接: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的更多相关文章
- hdu 1305 Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- HDU 1305 Immediate Decodability 可直接解码吗?
题意:一个码如果是另一个码的前缀,则 is not immediately decodable,不可直接解码,也就是给一串二进制数字给你,你不能对其解码,因解码出来可能有多种情况. 思路:将每个码按长 ...
- (step5.1.2)hdu 1305(Immediate Decodability——字典树)
题目大意:输入一系列的字符串,判断这些字符串中是否存在其中的一个字符串是另外一个字符串的前缀.. 如果是,输出Set .. is not immediately decodable 否则输出Set . ...
- Immediate Decodability HDU - 1305(模板trie)
求这些01串是否有一个是另一个的前缀.. 就是求次数就好了嘛...emm... 网上竟然都用指针写.... #include<cstdio> #include<iostream> ...
- hdu 1305 还是字典树
#include<cstdio> #include<iostream> #include<string> #include<cstdlib> #defi ...
- 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 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
随机推荐
- IP一些基础知识
1.主机IP地址 IP地址:internet上的每一台计算机都被赋予了唯一的32位Internet地址,简称ip地址. (1)IP地址的组成 IP地址由两部分组成,如图1 网络地址(net-ID) 主 ...
- c++11 中的 move 与 forward
[update: 关于左值右值的另一点总结,请参看这篇] 一. move 关于 lvaue 和 rvalue,在 c++11 以前存在一个有趣的现象:T& 指向 lvalue (左传引用), ...
- 不安装Oracle客户端使用PL/SQL连接服务器端Oracle
从10G开始,Oracle 提供了一个较为轻量级的客户包,叫做Instant Client Package. 将它安装好后,就不用再安装庞大的Oracle客户端,可以直接通过使用PL/SQL连接服务器 ...
- 嵌入在C++程序中的extern "C"
1.extern的作用 extern是C/C++语言中表明函数和全局变量作用范围(可见性)的关键字,可以告知编译器,用extern声明的函数和变量可以在本模块或其它模块中使用. 通常,在模块的头文件中 ...
- Struts2使用ModelDriven后JSON数据返回不正确
在struts.xml中加入<param name="root">action</param> <result name="exist&qu ...
- 纯servlet返回xml数据
... void doget..... response.setContentType("application/xml");//设置格式 PrintWriter out = r ...
- Android IOS WebRTC 音视频开发总结(五六)-- 如何测试网络性能?
本文主要介绍如何测试网络性能,文章来自博客园RTC.Blacker,欢迎关注微信公众号blacker,更多详见www.rtc.help 网络性能直接决定了视频通话效果,比如qq,很多时候我们我们觉得通 ...
- SMTP sendMail 失败解决办法
If you are seeing messages like this in your message log when running a process through the process ...
- C# 判断一字符串是否为合法数字(正则表达式)
判断一个字符串是否为合法整数(不限制长度) public static bool IsInteger(string s) { string pattern = @"^\d*$"; ...
- 记一次动态调用WebService
这次的使用参考博客园中的ID是 生命不息,折腾不止 http://www.cnblogs.com/leolion/p/4757320.html ,感谢分享 博客园让自己慢慢的成长,少不了这些无私奉献 ...