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 ...
随机推荐
- Ceph源码解析:PG peering
集群中的设备异常(异常OSD的添加删除操作),会导致PG的各个副本间出现数据的不一致现象,这时就需要进行数据的恢复,让所有的副本都达到一致的状态. 一.OSD的故障和处理办法: 1. OSD的故障种类 ...
- Dinic
BFS构造分层网络,DFS多路增广 #include<iostream> #include<vector> #include<queue> #include< ...
- log4
<?xml version="1.0"?> <configuration> <configSections> <section name= ...
- Mac OS X Server 安装与应用
Mac OS X Server 安装与应用 Mac OS X Server是苹果电脑公司新一代服务器软件.专为OS X和iOS设备.Mac OS X提供服务,现在支持Mavericks,能够轻松共享文 ...
- openstack openrpc
- iptable原理
http://www.cnblogs.com/littlehann/p/3708222.html http://seanlook.com/2014/02/23/iptables-understand/ ...
- (笔记)angular 包含关系的controller参数传递
- UML类图与类的关系详解
摘自:http://www.uml.org.cn/oobject/201104212.asp UML类图与类的关系详解 2011-04-21 来源:网络 在画类图的时候,理清类和类之间的关系是重点.类 ...
- leetcode 107
107. Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order trav ...
- mac ping ip地址
Mac下有个类似于Windows下CMD的模式叫做终端,但是这个模式和Windows下的CMD有着很大的差别. 工具/原料 Mac电脑一台 方法/步骤 首先通过菜单栏的搜索功能找到“终端”,也可以 ...