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 ...
随机推荐
- Hibernate使用时需要注意的几个小问题
今天晚上玩了一下JDBC连接数据库,之后又利用Hibernate进行了数据库的访问,感觉利用Hibernate对数据库访问在文件配置好了之后确实更加简单快捷. 但是在操作的过程中也有一些细节需要注意一 ...
- Nacos-作为Sring cloud 注册发现
Nacos:一个更易于构建云原生应用的动态服务发现.配置管理和服务管理平台. https://nacos.io/zh-cn/index.html 功能: 动态服务配置 服务发现和管理 动态DNS服务 ...
- THUPC/CTS/APIO2019划水记
THUPC:划水的咸鱼 CTS:打铁 APIO:压线cu 终于又回归了文化课. 落下10天的课程,OI又得停一停了 这次划水,又见识了许多的神仙,再一次被吊打 5.11~5.20,有太多的事情需要回忆 ...
- SQL server 聚集索引与主键的区别
主键是一个约束(constraint),他依附在一个索引上,这个索引可以是聚集索引,也可以是非聚集索引. 所以在一个(或一组)字段上有主键,只能说明他上面有个索引,但不一定就是聚集索引. 例如下面: ...
- elasticsearch 基础 —— Query String
使用查询解析器来解析其内容的查询.下面是一个例子: GET /_search { "query": { "query_string" : { "def ...
- SharePoint创建web应用程序,提示密码不正确
使用版本SharePoint2010: $username="domain\username"$newpassword="xxxxxxxx"stsadm -o ...
- 115-基于TI TMS320DM6467T Camera Link 机器视觉 智能图像分析平台
基于TI TMS320DM6467无操作系统Camera Link智能图像分析平台 1.板卡概述 该板卡是我公司推出的一款具有超高可靠性.效率最大化.无操作系统的智能视频处理卡,是机器视觉开发上的首选 ...
- zabbix基础之环境搭建
zabbix入门 环境部署 安装mysql #安装MySQL,官方的MySQL的repo源地址:http://repo.mysql.com/ #选择指定的MySQL版本,我这里选mysql5.7的版本 ...
- Codeforces Round #392 (Div. 2) - A
题目链接:http://codeforces.com/contest/758/problem/A 题意:给定N个城市的福利,国王现在想让每个城市的福利都一致.问最少需要花多少钱使得N个城市的福利值都一 ...
- Sass--调用混合宏
在 Sass 中通过 @mixin 关键词声明了一个混合宏,那么在实际调用中,其匹配了一个关键词“@include”来调用声明好的混合宏.例如在你的样式中定义了一个圆角的混合宏“border-radi ...