upc组队赛15 Lattice's basics in digital electronics【模拟】
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 second. In the next 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 0 and 1.
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 8-bit data there is 11 bit called parity bit, which should be '0' if there are odd number of '1's in the previous 8 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 9 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 3 parts:"101010101","010101010" and "101010". For the first part, there are 4 '1's in the first 8 bits, and parity bit is '1', so this part passed the check. For the second part, there are 4 '1's and parity bit is '0', so this part failed the check. For the third part, it has less than 9 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 8 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 N pairs of corresponding relations from a bit string Si to an ASCII code Ci, and the message length M, they want to peek his privacy so they come to you to write a program that decodes messages that LATTICE receives.
输入
The first line an integer T (T<35) represents the number of test cases.
Every test case starts with one line containing two integers, M(0<M≤100000), the number of original characters, and N(1≤N≤256), then N lines, every line contains an integer Ci, and a string Si(0<|Si|≤10), means that Si represents Ci, the ASCII code to a visible character and Si only contains '0' or '1' and there are no two numbers i and j that Si is prefix of Sj.
Then one line contains data that is going to be received in hexadecimal. (0<∣data∣<200000).
输出
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 M characters. Input guarantees that it will have no less than M valid characters and all given ASCII codes represent visible characters.
样例输入
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
题解
一个题目很长的模拟,但实际上真的不难
首先把输入的十六进制字符串转化成二进制,划分每9位一行
如果前8位中1的个数为奇数,并且第9位为0
或者前8位中1的个数为偶数,并且第9位为1
那么保留前8位,否则去掉这一行
将剩下的结果遍历,将二进制转化为输入的对应字符
代码
#include<iostream>
#include<cstdio> //EOF,NULL
#include<cstring> //memset
#include<cstdlib> //rand,srand,system,itoa(int),atoi(char[]),atof(),malloc
#include<limits.h> //INT_MAX
#include<bitset> // bitset<?> n
#include<cmath> //ceil,floor,exp,log(e),log10(10),hypot(sqrt(x^2+y^2)),cbrt(sqrt(x^2+y^2+z^2))
#include<algorithm> //fill,reverse,next_permutation,__gcd,
#include<iomanip> //setw(set_min_width),setfill(char),setprecision(n),fixed,
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<iterator>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ll long long
#define LL long long
inline ll read(){ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;}
#define read read()
#define pb push_back
#define mp make_pair
#define P pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define MOD 998244353
#define mod 1e9+7
#define N 1000005
const int maxn=10000;
int t;
int n,m,x;
string ss;
map<string,int> ap;
map<char,string> sl;
void Init()
{
sl['0'] = "0000";
sl['1'] = "0001";
sl['2'] = "0010";
sl['3'] = "0011";
sl['4'] = "0100";
sl['5'] = "0101";
sl['6'] = "0110";
sl['7'] = "0111";
sl['8'] = "1000";
sl['9'] = "1001";
sl['A'] = "1010";
sl['B'] = "1011";
sl['C'] = "1100";
sl['D'] = "1101";
sl['E'] = "1110";
sl['F'] = "1111";
sl['a'] = "1010";
sl['b'] = "1011";
sl['c'] = "1100";
sl['d'] = "1101";
sl['e'] = "1110";
sl['f'] = "1111";
}
int main()
{
std::ios::sync_with_stdio(false);
Init();
cin >> t;
while(t--)
{
ap.clear();
cin >> n >> m;
while(m--)
{
cin >> x;
cin >> ss;
ap[ss] = x;
}
cin >> ss;
string s;
for(int i = 0; i<ss.length();i++)
{
s+=sl[ss[i]];
}
int len = s.length();
int cnt = len/9;
string str;
for(int i = 0; i < cnt;i++)
{
int sum = 0;
string tmp;
for(int j = 9*i + 0 ; j < 9 * i + 8; j++)
{
if(s[j] =='1') sum++;
tmp+=s[j];
}
if((sum % 2 == 0 && s[9 * i + 8] == '1') ||(sum%2==1 && s[9 * i+ 8] =='0'))
{
str+= tmp;
}
}
string tmp;
string ans;
int tot = 0;
for(int i = 0; i < str.length();i++)
{
tmp+=str[i];
if(ap[tmp])
{
char c;
c = ap[tmp];
ans += c;
tmp.clear();
tot++;
if(tot == n) break;
}
}
cout << ans <<endl;
}
}
upc组队赛15 Lattice's basics in digital electronics【模拟】的更多相关文章
- ACM-ICPC2018沈阳网络赛 Lattice's basics in digital electronics(模拟)
Lattice's basics in digital electronics 44.08% 1000ms 131072K LATTICE is learning Digital Electron ...
- 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
原题链接:https://nanti.jisuanke.com/t/31450 附上队友代码:(感谢队友带飞) #include <bits/stdc++.h> using namespa ...
- 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
[链接] 我是链接,点我呀:) [题意] [题解] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [代码] #include <bits/stdc+ ...
- upc组队赛15 Supreme Number【打表】
Supreme Number 题目链接 题目描述 A prime number (or a prime) is a natural number greater than 1 that cannot ...
- upc组队赛15 Made In Heaven【第K短路 A*】
Made In Heaven 题目描述 One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with ...
- 沈阳网络赛I-Lattice's basics in digital electronics【模拟】
42.93% 1000ms 131072K LATTICE is learning Digital Electronic Technology. He is talented, so he under ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
随机推荐
- Codeforces 1093D(染色+组合数学)
题面 传送门 题目大意:给出一个无向图,每个节点可以填1,2,3三个数中的一个 问有多少种填数方案,使两个相邻节点的数之和为奇数 分析 如果图中有奇环,一定无解 我们对图黑白染色,由于图可能不联通,记 ...
- [暑假集训Day2T1]种树
标算是贪心,我写了个差分约束????? 设dist[i]表示1-i号土地种的树的总棵数,考虑以下几种约束条件: 1)dist[y]>=dist[x]+z,即x号土地至y号土地间至少种了z棵树 2 ...
- [JSOI2007]建筑抢修(贪心+后悔)
[JSOI2007]建筑抢修(贪心+后悔) 洛谷题目传送门 吐槽 这是一道经典的贪心后悔的题目 做过贪心加后悔的题目的应该一眼可以看出来 解题思路 首先按倒塌时间T2排序,再从1枚举到n,能修就修,发 ...
- redis setNx方法
Redis有一系列的命令,特点是以NX结尾,NX是Not eXists的缩写,如SETNX命令就应该理解为:SET if Not eXists.这系列的命令非常有用,这里讲使用SETNX来实现分布式锁 ...
- jsp常用代码
1.头部 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&q ...
- BZOJ1076/Luogu2473 奖励关(SCOI2008)状压DP+期望DP
题意:给n(n<=15)种宝物宝物有价值w且每个宝物有一个前置宝物(即你必须先吃过它的所有前置宝物至少一次才能吃该宝物),共有m轮游戏,每一轮会在n种宝物等概率选一个出来,因为宝物价值可正可负你 ...
- 创建 OpenStack云主机
创建过程 创建虚拟网络 创建m1.nano规格的主机(相等于定义虚拟机的硬件配置) 生成一个密钥对(openstack的原理是不使用密码连接,而是使用密钥对进行连接) 增加安全组规则(用iptable ...
- openstack组件之nova
Nova常用命令 1.查看vm列表 nova listnova list --all 2.查看镜像列表 nova image-list 3.查看卷列表 nova voluma-list 4.查 ...
- elasticsearch查询与sql对应关系
must: AND must_not:NOT should:OR
- bzoj4987 Tree 树上背包
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4987 题解 一道还不错的题咯. 很容易发现一个结论:这 \(k\) 个点构成的一定是一个连通块 ...