UVA1052 题意翻译

· · 闲话

原文

The aim of data compression is to reduce redundancy in stored or communicated data. This increases

effective data density and speeds up data transfer rates. One possible method to compress any binary

message is the following:

Replace any maximal sequence of n 1’s with the binary version of n whenever it shortens

the length of the message.

For example, the compressed form of the data 11111111001001111111111111110011 becomes 10000010011110011. The original data is 32 bits long while the compressed data is only 17 bits long.

The drawback of this method is that sometimes the decompression process yields more than one

result for the original message, making it impossible to obtain the original message. Write a program

that determines if the original message can be obtained from the compressed data when the length of the original message (L), the number of 1’s in the original message (N) and the compressed data are given. The original message will be no longer than 16 Kbytes and the compressed data will be no longer than 40 bits.

Input

The input file contains several test cases. Each test case has two lines. The first line contains L and N

and the second line contains the compressed data. The last case is followed by a line containing two zeroes.

Output

For each test case, output a line containing the case number (starting with 1) and a message ‘YES’, ‘NO’ or ‘NOT UNIQUE’. ‘YES’ means that the original message can be obtained. ‘NO’ means that the compressed data has been corrupted and the original message cannot be obtained. ‘NOT UNIQUE’ means that more than one message could have been the original message. Follow the format shown in the sample output.

Sample Input

32 26
10000010011110011
9 7
1010101
14 14
111111
00

Sample Output

Case #1: YES
Case #2: NOT UNIQUE
Case #3: NO

翻译

题目描述

数据压缩的目标是减少存储或传输数据中的冗余,以此提升有效数据密度、加快数据传输速率。
有一种可压缩任意二进制消息的可行方法如下:

只要能缩短消息长度,就将任意一段最长的连续n个1的序列替换为n的二进制形式。

举例来说,数据11111111001001111111111111110011的压缩形式为10000010011110011,原始数据共32位,而压缩后的数据仅17位。

这种方法的缺陷在于,有时解压过程会得到不止一种原始消息结果,导致无法还原出最初的原始消息。

请编写一个程序:在给定原始消息长度L、原始消息中1的个数N以及压缩数据的前提下,判断能否从压缩数据还原出唯一的原始消息。原始消息长度不超过16KB,压缩数据长度不超过40位。

输入说明

输入文件包含多组测试用例,每组测试用例占两行:

第一行包含L和N两个整数,第二行是压缩后的二进制数据。

所有测试用例结束后,会出现一行仅含两个0的输入作为终止标识。

输出说明

针对每组测试用例,输出一行内容:

包含用例编号(从1开始计数),以及对应结果标识——"YES"代表可以还原出唯一的原始消息;"NO"代表压缩数据已损坏,完全无法还原出符合条件的原始消息;"NOT UNIQUE"代表存在不止一种可生成该压缩数据的原始消息。

输出格式需参照样例输出呈现。

样例输入

32 26
10000010011110011
9 7
1010101
14 14
111111
00

样例输出

Case #1: YES
Case #2: NOT UNIQUE
Case #3: NO