UVa 644 Immediate Decodability
吐槽下我的渣渣英语啊,即使叫谷歌翻译也没有看懂,最后还是自己读了好几遍题才读懂。
题目大意:题意很简单,就是给一些互不相同的由'0','1'组成的字符串,看看有没有一个字符串是否会成为另一个的开头的子串。
直接简单粗暴的去比较就可以了。
这是原题:
| Immediate Decodability |
An 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:0000
but this one is not:
A:01 B:10 C:010 D:0000 (Note that A is a prefix of C)
Input
Write a program that accepts as input a series of groups of records from a data file. 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).
Output
For 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.
The Sample Input describes the examples above.
Sample Input
01
10
0010
0000
9
01
10
010
0000
9
Sample Output
Set 1 is immediately decodable
Set 2 is not immediately decodable
Miguel A. Revilla
2000-01-17
AC代码:
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; char code[][];
bool cmp(char s1[], char s2[]); int main(void)
{
#ifdef LOCAL
freopen("644in.txt", "r", stdin);
#endif
int kase = , n;
while(gets(code[]))
{
bool flag = false;
int i, j;
n = ;
while(code[n][] != '')
gets(code[++n]); for(i = ; i < n - ; ++i)
{
if(flag)
break;
for(j = i + ; j < n; ++j)
{
flag = cmp(code[i], code[j]);
if(flag) break;
}
} if(!flag)
printf("Set %d is immediately decodable\n", ++kase);
else
printf("Set %d is not immediately decodable\n", ++kase);
}
return ;
}
//比较一个字符串是否会成为另一个的开头的子串
bool cmp(char s1[], char s2[])
{
int l1 = strlen(s1);
int l2 = strlen(s2);
int lmin = min(l1, l2), i = ;
if(l1 == l2)//长度相等,必然不会是子串
return false;
for(i = ; i < lmin; ++i)
{
if(s1[i] != s2[i])
break;
}
if(i == lmin)
return true;
return false;
}
代码君
UVa 644 Immediate Decodability的更多相关文章
- UVA 644 Immediate Decodability (字符处理)
An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Volume 1. String(uva)
10361 - Automatic Poetry #include <iostream> #include <string> #include <cstdio> # ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 1(String)
第一题:401 - Palindromes UVA : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8 ...
- UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494
白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
随机推荐
- Kafka的coordinator
(基于0.10版本) Group Management Protocol Kafka的coordiantor要做的事情就是group management,就是要对一个团队(或者叫组)的成员进行管理. ...
- javascript设计模式-生成器模式(Builder)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ExtJs之单选及多选框
坚持 <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-eq ...
- 【hdu3341-Lost's revenge】DP压缩+AC自动机
题意:给定只含有A.G.C.T的n个模板串,一个文本串,文本串任意两个字母可互换位置,问最多能匹配多少个模板串.注意:匹配同一个模板串匹配了两次,ans+=2:(可重复) 题解: 原本想到一个简单dp ...
- a cold welcome
What does 'a cold welcome' refer to? On wednesday evening,we went to the town hall. It was the last ...
- 安卓四大组件之--service
服务:长期后台运行的没有界面的activity,程序写法和activity类似. 安卓系统进程管理是按照一定规则的: 1.默认情况下,关闭掉一个应用程序,清空了这个应用程序的任务栈,应用程序的进程还会 ...
- 网络安装之Redhat衍生版
GNU/Linux开源,这个意义实在是非常的广泛,目前在distrowatch上表现活跃的300个发行版代表了GNU/Linux的主流,然而细心的Linux爱好者会发现CentOS-based dis ...
- 天使投资、VC 以及 PE 的区别是什么?
如果满足于“阶段不同”这个简单的回答,那你可能错过了一个思考资本与企业发展之间关系的机会. 首先要交待一下,在大众语境中,angel/VC/PE三者都可认为是VC,也就是人们常说的风险投资,在国内官方 ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-004嵌套组件的注解AttributeOverrides
一.数据库 二.代码 1. package org.jpwh.model.advanced; import javax.persistence.AttributeOverride; import ja ...
- Bootstrap的clearfix
1.div的内容太多会导致后面的div错位 <!DOCTYPE html> <html> <head> <title>自定义占满wgnu</tit ...