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 ...
随机推荐
- LCT小结
LCT真是灵活好用… LCT的基本思想与树链剖分差不多,都是把树剖成一条条链,只不过LCT用的是SPLAY维护的,而且,SPLAY的链是会变化的,不像剖分是定死的. LCT最重要的操作就是access ...
- 金融证券协议FIX/FAST/STEP
金融信息交换协议FIX是适用于实时证券.金融电子交易的数据通信标准.它是把各类证券金融业务需求流程格式化,使之成为一个可用计 算机语言描述的功能流程,并在每个业务功能接口上统一交换格式.STEP(Se ...
- LVM quick start
这里记录一些任务用到的快速命令,详细LVM管理可参考: http://wenku.baidu.com/view/c29b8bc4bb4cf7ec4afed0ad.html 1.把home分区的磁盘空间 ...
- 深入JS第一天:原型和它的小伙伴们(一)
我在这里不说定义,找点问题,再解决问题. 一.原型 Q1:这样做输出的结果是什么? jQuery= String; jQuery.prototype.say = function () { alert ...
- IT主要在线学习网站
大的模式来说,目前做编程学习网站的大概有两种.一种是视频模式,如优才,麦可,开课吧等,一种是非视频模式如计蒜客(泡面吧),实验楼和他们汇智网等.其中多数产品的创新也都是在“视频+交互式学习”模式上.要 ...
- JavaWeb-Eclipse的下载和安装
Eclipse下载地址:http://www.eclipse.org/downloads/ Eclipse集成JDK 遇见弹框: 1.这是由于缺少JRE所导致的,Eclipse中带有自己的编译器,因此 ...
- UITbaleView上按钮的单选
设置Id属性,标记是哪个cell @property (nonatomic,assign)NSInteger Id; 设置一个普通状态和选中状态图片不同的按钮 _choose = [[UIButton ...
- Lock wait timeout exceeded; try restarting transaction
What gives this away is the word transaction. It is evident by the statement that the query was atte ...
- light oj 1393 - Crazy Calendar 博弈论
思路:当移到右下角时,就不能移动了.所以与右下角的奇偶性相同的位置,都不能直接到达,先手必败! 只需考虑与右下角奇偶不同的位置,可以看成NIM博弈.最后NIM和不为0的胜,否者败!! 代码如下: #i ...
- Linux网络编程6——使用TCP实现文件服务器
需求 当客户端连接上服务器后,服务器会将相应文件传输给客户端,实现文件下载. 思路 服务器端,主进程负责listen.循环内,主进程每从任务请求队列中accept出一个请求,就fork出孙子完成文件传 ...