• 42.93%
  • 1000ms
  • 131072K

LATTICE is learning Digital Electronic Technology. He is talented, so he understood all those pieces of knowledge in 10^{-9}10−9 second. In the next 10^{-9}10−9 second, he built a data decoding device that decodes data encoded with his special binary coding rule to meaningful words.

His coding rule is called "prefix code", a type of code system (typically a variable-length code) distinguished by its possession of the "prefix property", which requires that there is no whole code word in the system that is a prefix (initial segment) of any other code word in the system. Note that his code is composed of only 00 and 11.

LATTICE's device only receives data that perfectly matches LATTICE's rules, in other words, people who send message to LATTICE will always obey his coding rule. However, in the process of receiving data, there are errors that cannot avoid, so LATTICE uses parity check to detect error bytes, after every 88-bit data there is 11 bit called parity bit, which should be '0' if there are odd number of '1's in the previous 88 bits and should be '1' if there are even number of '1's. If the parity bit does not meet the fact, then the whole 99 bits (including the parity bit) should be considered as invalid data and ignored. Data without parity bit is also considered as invalid data. Parity bits will be deleted after the parity check.

For example, consider the given data "101010101010101010101010", it should be divided into 33parts:"101010101","010101010" and "101010". For the first part, there are 44 '1's in the first 88 bits, and parity bit is '1', so this part passed the check. For the second part, there are 44 '1's and parity bit is '0', so this part failed the check. For the third part, it has less than 99 bits so it contains no parity bit, so this part also failed the check. The data after parity check is "10101010", which is the first 88 bits of first part.

Data passed the parity check will go into a process that decodes LATTICE's code. The process is described in the following example: consider a situation that, "010" represents 'A' and "1011" represents 'B', if the data after parity check is "01010110101011010010", it can be divided into "010"+"1011"+"010"+"1011"+"010"+"010", which means "ABABAA" . LATTICE's device is so exquisite that it can decode all visible characters in the ASCII table .

LATTICE is famous for his Talk show, some reporters have sneaked into his mansion, they stole the data LATTICE to decode in hexadecimal, the coding rule consists of NN pairs of corresponding relations from a bit string S_iSi​ to an ASCII code C_iCi​, and the message length MM, they want to peek his privacy so they come to you to write a program that decodes messages that LATTICE receives.

Input

The first line an integer T\ (T<35)T (T<35) represents the number of test cases.

Every test case starts with one line containing two integers, M\ (0<M\leq100000)M (0<M≤100000), the number of original characters, and N\ (1\leq N \leq 256)N (1≤N≤256), then NN lines, every line contains an integer C_iCi​, and a string S_i(0<|S_i|\leq 10)Si​(0<∣Si​∣≤10), means that S_iSi​ represents C_iCi​, the ASCII code to a visible character and S_iSi​ only contains '0'or '1' and there are no two numbers ii and jj that S_iSi​ is prefix of S_jSj​.

Then one line contains data that is going to be received in hexadecimal. (0<|data|<200000)(0<∣data∣<200000).

Output

For each test case, output the decoded message in a new line, the length of the decoded message should be the same with the length of original characters, which means you can stop decoding having outputted MM characters. Input guarantees that it will have no less than MM valid characters and all given ASCII codes represent visible characters.

Hint

Lattice's encoding rule for test case 22:

ASCII code character lattice's code
4949 11 00010001
5050 22 0100101001
5151 33 011011

the device takes this input in hex

 

1

14DB24722698

input in binary

 
 

1

0001 0100 1101 1011 0010 0100 0111 0010 0010 0110 1001 1000

formatted into 66 lines, each line contains 88 data bits and one parity bit

 
 

1

00010100 1

2

10110110 0

3

10010001 1

4

10010001 0

5

01101001 1

6

000

parity check of the third line and the last line failed, so ignore those two lines.parity bits should also be ignored.

 
 

1

00010100

2

10110110

3

10010001

4

01101001

arrange those bits by the rules informed

 
 

1

0001 01001 011 011 01001 0001 011 01001

output the result

 
 

1

12332132

样例输入复制

2
15 9
32 0100
33 11
100 1011
101 0110
104 1010
108 00
111 100
114 0111
119 0101
A6Fd021171c562Fde1
8 3
49 0001
50 01001
51 011
14DB24722698

样例输出复制

hello world!!!!
12332132

题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

题意:

要你输出一个长度为m的字符串 给的是一定的编码 需要按照规则进行解码

给定n个字符的编码形式 保证是二进制的哈弗曼编码

每8位有一位偶校验位 如果错误这9位都不要 不够9位的也都舍去 如果正确校验位不要

输入一串十六进制的编码

思路:

模拟 分成几个步骤

用map存编码和字符的对应

首先把输入的十六进制编码转成二进制的形式

第二步 进行偶校验 得到有效的编码

第三步 找到编码对应的字符 输出


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<set>
//#include<bits/stdc++.h>
#define inf 0x7f7f7f7f7f7f7f7f
using namespace std;
typedef long long LL; const int maxn = 200005;
int t, m, n, len, checklen;
char hexdata[maxn], bindata[maxn * 4], findata[maxn * 4];
map<string, char>mp; void init()
{
mp.clear();
memset(hexdata, 0, sizeof(hexdata));
memset(bindata, 0, sizeof(bindata));
memset(findata, 0, sizeof(findata));
len = 0;
checklen = 0;
} void hextobin()
{
for (int i = 0; i < len; i++) {
int tmp;
if (hexdata[i] == 'A' || hexdata[i] == 'a') {
tmp = 10;
}
else if (hexdata[i] == 'B' || hexdata[i] == 'b') {
tmp = 11;
}
else if (hexdata[i] == 'C' || hexdata[i] == 'c') {
tmp = 12;
}
else if (hexdata[i] == 'D' || hexdata[i] == 'd') {
tmp = 13;
}
else if (hexdata[i] == 'E' || hexdata[i] == 'e') {
tmp = 14;
}
else if (hexdata[i] == 'F' || hexdata[i] == 'f') {
tmp = 15;
}
else {
tmp = hexdata[i] - '0';
} for (int j = 3; j >= 0; j--) {
bindata[i * 4 + j] = (tmp & 1) + '0';
tmp >>= 1; }
//cout<<bindata<<endl;
} //printf("%s\n", bindata);
} void check()
{
int cnt = 0, tmplen = 0;
checklen = 0;
char tmp[10];
for (int i = 0; i < len * 4; i++) {
if ((i + 1) % 9 == 0) {
if ((cnt % 2) ^ (bindata[i] - '0')) {
for (int i = 0; i < tmplen; i++) {
findata[checklen++] = tmp[i];
}
}
cnt = 0;
tmplen = 0;
memset(tmp, 0, sizeof(tmp));
}
else {
tmp[tmplen++] = bindata[i];
if (bindata[i] == '1') {
cnt++;
}
}
} //printf("%s\n", findata);
} void solve()
{
string tmp = "";
int tmpcnt = 0;
for (int i = 0; i < checklen; i++) {
tmp += findata[i];
if (mp.find(tmp) == mp.end()) {
continue;
}
else {
printf("%c", mp[tmp]);
//cout<<tmp<<endl;
tmpcnt++;
if(tmpcnt == m){
break;
}
tmp = "";
}
}
printf("\n");
} int main()
{
cin >> t;
while (t--) {
init();
scanf("%d%d", &m, &n);
for (int i = 0; i < n; i++) {
int d;
scanf("%d ", &d);
string s;
cin >> s;
mp[s] = (char)(d);
}
cin >> hexdata;
len = strlen(hexdata);
hextobin();
check();
solve();
}
return 0;
}

沈阳网络赛I-Lattice's basics in digital electronics【模拟】的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区网络预赛 I Lattice's basics in digital electronics(模拟)

    https://nanti.jisuanke.com/t/31450 题意 给出一个映射(左为ascll值),然后给出一个16进制的数,要求先将16进制转化为2进制然后每9位判断,若前8位有奇数个1且 ...

  2. ACM-ICPC 2018 沈阳赛区网络预赛 I. Lattice's basics in digital electronics 阅读题加模拟题

    题意:https://nanti.jisuanke.com/t/31450 题解:题目很长的模拟,有点uva的感觉 分成四步 part1 16进制转为二进制string 用bitset的to_stri ...

  3. ACM-ICPC2018沈阳网络赛 Lattice's basics in digital electronics(模拟)

    Lattice's basics in digital electronics 44.08% 1000ms 131072K   LATTICE is learning Digital Electron ...

  4. upc组队赛15 Lattice's basics in digital electronics【模拟】

    Lattice's basics in digital electronics 题目链接 题目描述 LATTICE is learning Digital Electronic Technology. ...

  5. 【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice's basics in digital electronics

    [链接] 我是链接,点我呀:) [题意] [题解] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [代码] #include <bits/stdc+ ...

  6. ACM-ICPC 2018 沈阳赛区网络预赛 I 题 Lattice's basics in digital electronics

    原题链接:https://nanti.jisuanke.com/t/31450 附上队友代码:(感谢队友带飞) #include <bits/stdc++.h> using namespa ...

  7. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  8. 沈阳网络赛 F - 上下界网络流

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  9. 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】

    Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...

随机推荐

  1. mysql驱动(github上的)

    https://github.com/Eonblast/Emysql https://github.com/denglf/erlang-db-driver https://github.com/diz ...

  2. 【Java面试题】35 List, Set, Map是否继承自Collection接口?

    Collection是最基本的集合接口,声明了适用于JAVA集合(只包括Set和List)的通用方法. Set 和List 都继承了Conllection:Set具有与Collection完全一样的接 ...

  3. 实现QQ第三方登录教程(php)

    参看地址:http://www.bcty365.com/content-10-2945-1.html

  4. 不错的源码演示:admin5源码

    admin5源码官网:http://down.admin5.com/ 集资讯,源码,字体,itchat于一体的网站,可以下载喔! 实际项目中可以用得到.

  5. Oracle-批量修改语句及相关知识点

    问: 有两张表A和B,结构相同,数据量一致,比如都有x,y和z列且都有n行,x为主键,完全相等,如何把表B的y列的数据赋值给A的y列? 我写的是1 update A set A.y=B.y where ...

  6. centos7 安装zookeeper 集群

    data 创建myid  设置1 zookeeper默认端口2181  同步端口 20881 和 30881 设置zoo.cfg文件

  7. TTCN中PTC的执行流程

    一些概念 Component(測试组件或者測试成分),TTCN接触下来最频繁的就是MTC(Main Test Component,主測试组件),在执行測试用例前,须要首先创建一个MTC.在testca ...

  8. linux 启动时文件系统错误

    由于我把/dev/VolGroup00/lvData写在了/etc/fstab中,后面又把这个lv给删除了,导致出现下面开机启动的错误: 解决办法: 1.进入单用户模式下,当修改/etc/fstab时 ...

  9. N32903系列的基础知识(1)

    N32903U1DN使用ARM926EJ-S内核,其内部集成的JPEG编解码器.CMOS摄像头接口.32通道的声音处理单元(SPU).ADC.DAC等不仅可以满足各种的应用需求,还能减少生产方面的物料 ...

  10. unix:/tmp/php-cgi.sock

    为什么要用unix:/tmp/php-cgi.sock,最主要的特征就是unix socket比tcp快,当网站流量大的时候,服务器的优化是分毫必争的. 当我们用php-fpm来管理我们的php启动时 ...