ACM-ICPC2018沈阳网络赛 Lattice's basics in digital electronics(模拟)
Lattice's basics in digital electronics
- 44.08%
- 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
14DB24722698
input in binary
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
00010100 1
10110110 0
10010001 1
10010001 0
01101001 1
000
parity check of the third line and the last line failed, so ignore those two lines.parity bits should also be ignored.
00010100
10110110
10010001
01101001
arrange those bits by the rules informed
0001 01001 011 011 01001 0001 011 01001
output the result
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
题目来源
大模拟,进制转换解码。900ms...多交几发就过了
#include<bits/stdc++.h>
#define MAX 15
using namespace std;
typedef long long ll; int x;
char y[MAX];
string s,ss;
map<string,int> mp;
string bb(char x){
if(x=='') return "";if(x=='') return "";
if(x=='') return "";if(x=='') return "";
if(x=='') return "";if(x=='A'||x=='a') return "";
if(x=='') return "";if(x=='B'||x=='b') return "";
if(x=='') return "";if(x=='C'||x=='c') return "";
if(x=='') return "";if(x=='D'||x=='d') return "";
if(x=='') return "";if(x=='E'||x=='e') return "";
if(x=='') return "";if(x=='F'||x=='f') return "";
}
int find(string s){
int c=;
for(int i=;i<s.length();i++){
if(s[i]=='') c++;
}
return c;
}
int main()
{
int t,n,m,i,j;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
mp.clear();
for(i=;i<=m;i++){
scanf("%d %s",&x,y);
mp[y]=x;
}
cin>>s;
ss="";
int len=s.length();
for(i=;i<len;i++){
ss+=bb(s[i]);
}
s="";
len=ss.length();
for(i=;i<len;i+=){
if(i+>=len) break;
if((find(ss.substr(i,))&)!=ss[i+]-'') s+=ss.substr(i,);
}
len=s.length();
for(i=;i<len;i++){
if(n<=) break;
for(j=i;j<len;j++){
if(mp[s.substr(i,j-i+)]){
printf("%c",mp[s.substr(i,j-i+)]);
n--;i=j;
break;
}
}
}
printf("\n");
}
return ;
}
ACM-ICPC2018沈阳网络赛 Lattice's basics in digital electronics(模拟)的更多相关文章
- 沈阳网络赛I-Lattice's basics in digital electronics【模拟】
42.93% 1000ms 131072K LATTICE is learning Digital Electronic Technology. He is talented, so he under ...
- upc组队赛15 Lattice's basics in digital electronics【模拟】
Lattice's basics in digital electronics 题目链接 题目描述 LATTICE is learning Digital Electronic Technology. ...
- ACM-ICPC 2018 沈阳赛区网络预赛 I Lattice's basics in digital electronics(模拟)
https://nanti.jisuanke.com/t/31450 题意 给出一个映射(左为ascll值),然后给出一个16进制的数,要求先将16进制转化为2进制然后每9位判断,若前8位有奇数个1且 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 I. Lattice's basics in digital electronics 阅读题加模拟题
题意:https://nanti.jisuanke.com/t/31450 题解:题目很长的模拟,有点uva的感觉 分成四步 part1 16进制转为二进制string 用bitset的to_stri ...
- 【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice's basics in digital electronics
[链接] 我是链接,点我呀:) [题意] [题解] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [代码] #include <bits/stdc+ ...
- ACM-ICPC 2018 沈阳赛区网络预赛 I 题 Lattice's basics in digital electronics
原题链接:https://nanti.jisuanke.com/t/31450 附上队友代码:(感谢队友带飞) #include <bits/stdc++.h> using namespa ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- HDU 5901 Count primes (2016 acm 沈阳网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...
随机推荐
- 九度OJ 1167:数组排序 (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5395 解决:1715 题目描述: 输入一个数组的值,求出各个值从小到大排序后的次序. 输入: 输入有多组数据. 每组输入的第一个数为数组的 ...
- Javascript模块化编程-初识[1]
JS模块化编程,已经成为一个迫切的需求.理想情况下,开发者只需要实现核心业务逻辑,其他都可以加载别人已经写好的模块. 但是,JS不是一种模块化编程语言,它不支持类,所以没有严格意义上的模块.为了实现模 ...
- python 创建一个实例:步骤一 编写一个构造函数
编写一个构造函数 #在python中,person 类的第一件是就是记录关于人员的基本信息,这叫做实例对象属性,并且它们通常通过给类方法函数中的self 属性赋值来创建. #赋给实力属性第一个值得通常 ...
- abap 打开文件对话框
[转自 http://blog.csdn.net/zhongguomao/article/details/6712576] *----------------------- Method 1 ---- ...
- LeetCode:奇偶链表【328】
LeetCode:奇偶链表[328] 题目描述 给定一个单链表,把所有的奇数节点和偶数节点分别排在一起.请注意,这里的奇数节点和偶数节点指的是节点编号的奇偶性,而不是节点的值的奇偶性. 请尝试使用原地 ...
- [Android] Gradle 安装
Gradle安装非常简单,只要从官网下载压缩包,解压,修改一下环境变量即可. 笔者写本篇随笔时,版本是1.12. Windows下安装 1 到官网(http://www.gradle.org/down ...
- Linux 下使用C语言 gets()函数报错
在Linux下,使用 gets(cmd) 函数报错:warning: the 'gets' function is dangerous and should not be used. 解决办法:采用 ...
- Compiling: main.cpp /bin/sh: g++: not found
Kbuntu用codeblocks编写C程序的时候,编译报错如下: Compiling: main.cpp/bin/sh: g++: not found 解决方法: sudo apt-get inst ...
- JAVA-关键字&标识符
关键字: 关键字就是在java程序中具备特殊含义的标识符.关键字一般用于描述一个程序的结构或者表示数据类型.他们用来表示一种数据类型,或者表示程序的结构等,关键字不能用作变量名.方法名.类名.包名. ...
- jQuery 中的常用函数
on() : 方法在被选元素及子元素上添加一个或多个事件处理程序.自1.7 版本起,on()方法是 bind(),live() 和 delegate()方法的替代品 语法: $(selector).o ...