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

时间:2023-03-09 21:55:55
ACM-ICPC 2018 沈阳赛区网络预赛  I. Lattice's basics in digital electronics 阅读题加模拟题

题意:https://nanti.jisuanke.com/t/31450

题解:题目很长的模拟,有点uva的感觉

分成四步

part1 16进制转为二进制string 用bitset的to_string()

part2 parity check 校对,将处理结果pushback到另一个string

part3 建字典树,用形如线段树的数组存

part4 遍历字典树

1A 233

#include<bitset>
#include <cstdio>
#include <cmath>
#include <complex>
#include <algorithm>
#include <iostream>
#include<string.h>
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
const int maxn = 8e5; int tot = ;
const int MAXN = ;
bitset<maxn>bi;
bitset<>buff[+];
char s[ + ];
char tree[ * ];
int n;
string ss;
string cd;
int main()
{ int t; cin >> t; while (t--) {
ss.clear();
cd.clear();
mmm(tree, );
int n,m;
cin >> m >> n;
rep(i, , n) {
int x;
char op[];
cin >> x >> op;
int len = strlen(op);
int now = ;
rep(j, , len - ) {
if (op[j] == '') now = now * + ;
else now = now * ;
}
tree[now] = (char)x;
}
scanf("%s", s);
int len = strlen(s);
int tot = ;
rep(i, , len - ) {
if (isdigit(s[i]))buff[tot++] = s[i] - ;
else if (s[i] >= 'a'&&s[i] <= 'z')buff[tot++] = s[i] - 'a' + ;
else buff[tot++] = s[i] - 'A' + ;
}
//rep(i, 0, tot - 1)cout << buff[i] ;cout << endl; rep(i, , tot - )
ss += buff[i].to_string();
len = ss.length();
int cnt = ;
rep(i, , len-) {
if (i % == ) {
if (cnt % == && ss[i] == ''|| cnt % == && ss[i] == '') {
string temp = ss.substr(i - , );
cd += temp;
}
}
if (i % == )cnt = ;
if (ss[i] == '')cnt++;
}
len = cd.length();
rep(i, , len - ) {
int now = ;
while (now == || !tree[now]) {
if (cd[i] == '') now = now * + ;
else now = now * ;
i++;
}
printf("%c", tree[now]); m--;
if (m == )break;
i--;
}
cout << endl;
}
cin >> t;
return ;
}
/*
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
*/