B3900 [NICA #3] 数字显示屏 题解
YuiYuigahama · · 个人记录
前言
这是一道打表题。
解法
看到这种只有两种像素的,考虑把整个图像压成一个
上面的
#include <bits/stdc++.h>
std :: string a[10] = {
"111101101101111",
"001001001001001",
"111001111100111",
"111001111001111",
"101101111001001",
"111100111001111",
"111100111101111",
"111001001001001",
"111101111101111",
"111101111001111",
};
int main () {
std :: ios :: sync_with_stdio (false);
for(int i = 0; i < 10; i++) {
int c = 0;
for (char j : a[i])
(c <<= 1) |= j & 1;
std :: cout << "m[" << c << "] = " << i << ",\n";
}
return 0;
}
然后把图像爬下来和 map 里面存的数对比即可。
示例代码:
#include <bits/stdc++.h>
int main () {
std :: ios :: sync_with_stdio (false);
std :: map <int, int> m;
m[31599] = 0,
m[4681] = 1,
m[29671] = 2,
m[29647] = 3,
m[23497] = 4,
m[31183] = 5,
m[31215] = 6,
m[29257] = 7,
m[31727] = 8,
m[31695] = 9;
int n; std :: cin >> n;
std :: vector <std :: string> a (5);
for (auto &i : a) std :: cin >> i;
for(int i = 0; i < n; i++){
int c = 0;
for(int j = 0; j < 5; j++)
for(int k = 0; k < 3; k++)
(c <<= 1) |= a[j][(i << 2) + k] == '*';
std :: cout << m[c];
}
std :: cout << std :: endl;
return 0;
}