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 ...
随机推荐
- jquery是如何清除ajax缓存的
大家都知道万恶的IE在ajax中往往只读取第一次ajax请求时候的数据,其余时候都是从cache提取数据,(太懒了T_T).原生的JS清除ajax缓存的方法多,但是终觉有点繁琐,如果是用jquery的 ...
- 无法读取配置节“protocolMapping”,因为它缺少节声明
无法读取配置节“protocolMapping”,因为它缺少节声明 1.正常情况 : Web.config文件中有protocolMapping节点, 发现在IIS部署时使用了.NET 2.0的 ...
- No.011 Container With Most Water
11. Container With Most Water Total Accepted: 86363 Total Submissions: 244589 Difficulty: Medium Giv ...
- 如何使用编辑模板在ASPxGridView中进行新增修改(除去常规的gridviw模板编辑外)
aspgridview模板编辑效果图: //前端代码:(核心: <Templates><EditForm>.....中间可用栅格样式布局等(随意)...</Templat ...
- JavaBean和内省
JavaBean和内省 JavaBean是一个遵循特定的写法的java类 1. 必须有一个无参的构造方法 2.属性私有化 3.私有你给的属性必须通过public类型的方法暴露给 ...
- 分区的4k对齐
4k对齐的原理 4k对齐的磁盘性能比非对齐的大致提升在5%-10%左右. fdisk -H 224 -S 56 /dev/sdx #创建分区 fdisk -lu /dev/sdx #验证对齐
- 八、Linux下的网络服务器模型
服务器设计技术有很多,按使用的协议来分有TCP服务器和UDP服务器,按处理方式来分有循环服务器和并发服务器. 在网络程序里面,一般来说都是许多客户对应一个服务器,为了处理客户的请求,对服务端的程序就提 ...
- Android:控件布局(表格布局)TableLayout
TableLayout继承LinearLayout 实例:用表格布局实现计算机布局>>>>>>>>>>>> 有多少个TableR ...
- 2.1Android底层开发需要哪些工具
开发.测试和调试Linux驱动.HAL程序库需要的工具: (1)JDK6或以上版本: (2)Eclipse3.4或以上版本: (3)ADT(用于开发Android应用程序): (4)CDT(用于开发A ...
- 安装zabbix
安装zabbix 1. 准备好lamp架构(安装好mysql,php) 2.在数据库中授权: MariaDB [(none)]> create database zabbix charset u ...