hdu1305(字典树)
来源:互联网 发布:日本原单淘宝店 编辑:程序博客网 时间:2024/06/05 06:53
Immediate Decodability
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3770 Accepted Submission(s): 1977Problem DescriptionAn encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the prefix of a code for another symbol. We will assume for this problem that all codes are in binary, that no two codes within a set of codes are the same, that each code has at least one bit and no more than ten bits, and that each set has at least two codes and no more than eight.Examples: Assume an alphabet that has symbols {A, B, C, D}The following code is immediately decodable:A:01 B:10 C:0010 D:0000but this one is not:A:01 B:10 C:010 D:0000 (Note that A is a prefix of C)InputWrite a program that accepts as input a series of groups of records from input. Each record in a group contains a collection of zeroes and ones representing a binary code for a different symbol. Each group is followed by a single separator record containing a single 9; the separator records are not part of the group. Each group is independent of other groups; the codes in one group are not related to codes in any other group (that is, each group is to be processed independently).OutputFor each group, your program should determine whether the codes in that group are immediately decodable, and should print a single output line giving the group number and stating whether the group is, or is not, immediately decodable.Sample Input0110001000009011001000009Sample OutputSet 1 is immediately decodableSet 2 is not immediately decodableSourcePacific Northwest 1998RecommendEddy | We have carefully selected several similar problems for you: 1247 1251 1304 1298 1306#include<cstdio>#include<iostream>#include<algorithm>#include<string.h>using namespace std;struct node{int a[10];int isleaf;int haveson;}trie[1000];int len;int cnt;int f;char s[100];void insert(int now,int x){if(x==len){if(trie[now].isleaf==1||trie[now].haveson==1) {f=1;}trie[now].isleaf=1;return;}if(trie[now].isleaf==1){ f=1; return; } trie[now].haveson=1;int num=s[x]-'0';if(trie[now].a[num]==0) trie[now].a[num]=++cnt;insert(trie[now].a[num],x+1);}int main(){int t=0;int cas=0;cnt=0;memset(trie,0,sizeof(trie));while(scanf("%s",s)!=EOF){if(s[0]-'0'==9){cas++;if(t) printf("Set %d is not immediately decodable\n",cas);else printf("Set %d is immediately decodable\n",cas);memset(trie,0,sizeof(trie));t=0;cnt=0;}f=0;len=strlen(s);insert(0,0);if(f==1) t=1; } return 0;}
阅读全文0 0
- hdu1305字典树
- hdu1305之字典树
- hdu1305(字典树)
- hdu1305(字典树)
- hdu1305 Immediate Decodability (字典树)
- hdu1305-Immediate Decodability 字典树
- hdu1305-Immediate Decodability 字典树
- hdu1305 Immediate Decodability(字典树)
- hdu1305 字典树水题
- poj1056 & hdu1305 & zoj1808 Immediate Decodability(字典树变形)
- HDU1305(二叉树)
- ZOJ1808 POJ1056 HDU1305 Immediate Decodability,Trie树
- Immediate Decodability(hdu1305)
- HDU1305 Immediate Decodability
- hdu1305 Immediate Decodability
- HDU1305——Immediate Decodability
- 字典树
- 字典树
- MySQL数据备份和还原
- 用两个栈实现队列
- Java线程池机制源码分析
- 数据库连接池c3p0和dbcp
- Manacher算法——找字符串最长的回文子串
- hdu1305(字典树)
- fisher线性判别
- php编程注意点
- 浅谈电子商务网站购物车
- 棱镜门事件-引人深思IT技术发展的道德伦理问题
- 用注解形式装配Bean
- 添加信息提交页面
- CCF 201612-03 权限查询 题解
- 咏我俣嫌防中粱乘诹唾亓屑伟吧弛
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
黄耳的功效与作用
黄胄
黄胄作品
黄胄简介
黄胄作品价格
黄胄作品拍卖价格
黄胄的画多少钱一平尺
黄胜
黄胜依
中华会计网黄胜
厦门鼓浪屿黄胜记
黄胶
黄原胶是什么
黄原胶的危害
黄原胶报价
黄原胶的用途
塑料除黄剂
黄原胶 价格
黄胶胶水
黄原胶作用
黄原胶的作用
什么是黄原胶
机黄
黄胶条
耐黄变环氧树脂
黄原胶 作用
双面胶黄胶
湿胶和干胶
黄原胶图片
黄能
黄脸
黄自
黄芝
黄芩功效
黄芩图片
复方黄芩片
中药黄芩
黄芩汤
黄芩胶囊
黄芩口服液
黄芩片