Lattice's basics in digital electronics

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 沈阳赛区网络预赛

#include<iostream>
#include<bits/stdc++.h>
#include<map>
#include<cstdio>
using namespace std;
string s,t,ss,tt,ans,cnt;
int k,n;
int ma;
map<string,int>mp;
map<char,string>mp2;
int main(){
mp2[‘1‘]="0001";mp2[‘2‘]="0010";mp2[‘3‘]="0011";mp2[‘4‘]="0100";mp2[‘0‘]="0000";
mp2[‘5‘]="0101";mp2[‘6‘]="0110";mp2[‘7‘]="0111";mp2[‘8‘]="1000";mp2[‘9‘]="1001";
mp2[‘a‘]=mp2[‘A‘]="1010";mp2[‘b‘]=mp2[‘B‘]="1011";mp2[‘c‘]=mp2[‘C‘]="1100";mp2[‘d‘]=mp2[‘D‘]="1101";
mp2[‘e‘]=mp2[‘E‘]="1110";mp2[‘f‘]=mp2[‘F‘]="1111";
   int T;
   cin>>T;
   while(T--)
   {
       s="";
       cin>>k>>n;
       mp.clear();
       ans="";
       for(int i=1;i<=n;i++)
       {
           cin>>ma>>t;
           mp[t]=ma;
       }
       cin>>ss;for(int i=0;i<ss.size();i++){
            s+=mp2[ss[i]];}

       for(int i=0;i<s.size();i=i+9){
            tt="";
            int flag=0;
        if(i+9<=s.size()){
      for(int j=i;j<=i+7;j++)
      {
          if(s[j]==‘1‘)
            flag++;
            tt+=s[j];
      }
      if(flag%2==0&&s[i+8]==‘1‘)
        ans+=tt;
      if(flag%2==1&&s[i+8]==‘0‘)
        ans+=tt;
    }}
    //cout<<ans<<endl;
    for(int i=0,j=0;i<ans.size()&&j<k;i++)
    {
        cnt+=ans[i];
        if(mp[cnt])
        {
            printf("%c",mp[cnt]);
            j++;
            cnt="";
        }
    }
    puts("");
   }
}
 

Lattice's basics in digital electronics

原文地址:https://www.cnblogs.com/Yum20/p/9611681.html

时间: 2024-08-09 15:11:50

Lattice's basics in digital electronics的相关文章

[模拟] Lattice&#39;s basics in digital electronics

题目链接:https://www.jisuanke.com/contest/1556/105551 代码如下: 1 #include <iostream> 2 #include <bits/stdc++.h> 3 using namespace std; 4 const int maxn = 1e5+50; 5 map<string,int> mp; 6 map<char,int>mpp; 7 int m,n,x; 8 string str; 9 strin

【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice&#39;s basics in digital electronics

[链接] 我是链接,点我呀:) [题意] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [题解] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define all(x) x.begin(),x.end(

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

A. Gudako and Ritsuka 留坑 B. Call of Accepted 留坑 C. Convex Hull 留坑 D. Made In Heaven 留坑 E. The cake is a lie 留坑 F. Fantastic Graph 留坑 G. Spare Tire 留坑 H. Hamming Weight 留坑 I. Lattice's basics in digital electronics 留坑 J. Ka Chang 留坑 K. Supreme Number

2018 ACM 网络选拔赛 沈阳赛区

B. Call of Accepted 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #incl

Using QEMU for Embedded Systems Development

http://www.opensourceforu.com/2011/06/qemu-for-embedded-systems-development-part-1/ http://www.opensourceforu.com/2011/07/qemu-for-embedded-systems-development-part-2/ http://www.opensourceforu.com/2011/08/qemu-for-embedded-systems-development-part-3

科技文献检索

The Fundamentals of Three-Phase Power Measurements Application Note Introduction Although single-phase electricity is used to supply common domestic and office electrical appliances, three-phase alternating current (a.c.) systems are almost universal

Transistor 晶体管 场效应 双极型 达林顿 CMOS PMOS BJT FET

Transistor Tutorial Summary Transistor Tutorial Summary Bipolar Junction Transistor Tutorial We can summarise this transistors tutorial section as follows: The Bipolar Junction Transistor (BJT) is a three layer device constructed form two semiconduct

计算机电子书 2018 BiliDrive 备份

下载方式 根据你的操作系统下载不同的 BiliDrive 二进制. 执行: bilidrive download <link> 链接 文档 链接 Webpack 中文指南.epub (409.01 KB) bdrive://ce58b7b58292296a61a97de1f89c62b66da24ab6 OpenIntro Statistics 3e.pdf (7.17 MB) bdrive://ef01910ee34f0a1c91d9435f750a49c6ac1bc5fa AngularJ

http://www.apple.com/customer-letter/

Typora Writingshtml, body {overflow-x: initial !important;}html { font-size: 14px; } body { margin: 0px; padding: 0px; height: auto; bottom: 0px; top: 0px; left: 0px; right: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: