1305 Immediate Decodability(字典树)
来源:互联网 发布:淘宝售假次数如何计算 编辑:程序博客网 时间:2024/06/01 10:04
Immediate Decodability(链接)
Sample Input
0110001000009011001000009
Sample Output
Set 1 is immediately decodableSet 2 is not immediately decodable
//模板题
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;const int maxn = 2;struct node{ node *next[maxn]; int num;}root;node *newnode(){ node *p = new node; p->num = 0; p->next[0] = NULL; p->next[1] = NULL; return p;}int buildTree(node *root,char *t){ int len = strlen(t); node *p = root; for(int i=0;i<len;i++) { int a=t[i]-'0'; if(p->num!=0) return 0; if(p->next[a]==NULL) p->next[a]=newnode(); p=p->next[a]; } if(p->next[0]==NULL&&p->next[1]==NULL&&p->num==0) { p->num = 1; return 1; } else return 0;}void freeTree(node *p){ for(int i=0;i<2;i++) { if(p->next[i]) freeTree(p->next[i]); } free(p);}char str[1010][1010];int main(){ int Case = 1,n=0,i,m; node *head; while(~scanf("%s",&str[n++])) { if(str[n-1][0]=='9') { head=newnode(); for(i=0;i<n-1;i++) { m = buildTree(head,str[i]); if(m==0) break; } if(i==n-1) printf("Set %d is immediately decodable\n",Case++); else printf("Set %d is not immediately decodable\n",Case++); n=0; freeTree(head); } } return 0;}
阅读全文
0 0
- HDU 1305 Immediate Decodability (字典树)
- 1305 Immediate Decodability(字典树)
- IMMEDIATE DECODABILITY(字典树)
- Immediate Decodability 字典树
- IMMEDIATE DECODABILITY(字典树)
- Immediate Decodability-字典树
- hdoj Immediate Decodability 1305 (字典树判断前缀)
- hdu 1305 Immediate Decodability (字典树入门)
- 杭电acm 1305Immediate Decodability(字典树)
- hdu 1305 Immediate Decodability(字典树)
- Hdu 1305 Immediate Decodability 字典树
- hdu 1305 Immediate Decodability (字典树)
- hdu 1305 Immediate Decodability 字典树
- hdu 1305 Immediate Decodability 简单字典树
- hdu 1305 Immediate Decodability E字典树
- hdu 1305-Immediate Decodability(字典树)
- poj1056 IMMEDIATE DECODABILITY (字典树)
- 【hdu】 Immediate Decodability (字典树)
- 一张图看尽 Linux 内核运行原理
- 认识kettle
- 敏捷开发介绍
- HDU 5952 Counting Cliques(无向图定向搜索)
- C和指针之字符串编程练习6
- 1305 Immediate Decodability(字典树)
- 自定义类型(结构体、位段、枚举和联合)
- Statement、 PreparedStatement 、CallableStatement 区别和联系
- 在 Linux 下使用 find 指令查詢目錄與檔案的速查筆記
- jQuery
- 【hdu 4970】 Killing Monsters 【2014 Multi-University Training Contest 9 】
- Log4j2入门(1)-控制台日志输出
- SSH Secure Shell 无法登录:server responded "algorithm negotiation failed”
- 渣渣的TensorFlow学习笔记之strides和kernel影响尺寸变化