跳到正文

个人记录

B3900 [NICA #3] 数字显示屏 题解

YuiYuigahama约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年12月15日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 2 分钟

版本

  1. v1当前

前言

这是一道打表题。

解法

看到这种只有两种像素的,考虑把整个图像压成一个 1515 位的二进制数打表。

上面的 0101 可以手动快速输入,而后可以很简单地写出如下的打表程序:

C++
#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 里面存的数对比即可。

示例代码:

C++
#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;
}
原文