0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

競プロ日記#/25/03/24

Posted at

アルゴ式-電光掲示板

  • 0~9の表示パターンについて配列で管理することは思いついたが文字列の方が良いらしい。2進数のintで管理してしまった。
vector<string> mask = {
    "1110111", "0100100", "1011101", "1101101", "0101110",
"1101011", "1111011", "0100111", "1111111", "1101111"
};
  • あとは入力Nがそのままインデックス番号として使えるのでmask.[N]を整数値に変換する
int result = bitset<7.(mask[N]).to_ulong();
  • 文字列のビット→bitset()でN個のビットに変換→to_ulong()で整数値に

アルゴ式-電光掲示板の切り替え

  • まとめてフラグを消すで扱った「A = A and ~M」を応用すれば解ける
  • 今回は「切り替える」なので上記の例でいうと「A→~M」だけじゃなくて「M→~A」も必要になる
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

using Graph = vector<vector<int>>;

int main() {
    int N,M;
    cin >> N >> M;

    vector<string> mask = {
        "1110111", "0100100", "1011101", "1101101", "0101110",
    "1101011", "1111011", "0100111", "1111111", "1101111"
    };
    int newN = bitset<7>(mask.at(N)).to_ulong();
    int newM = bitset<7>(mask.at(M)).to_ulong();
    int ans = (newN & ~newM) | (newM & ~newN);
    cout <<  ans << endl;

}
  • ちなみに「&」のところを「and」にすると挙動がバグる。正直よくわからなかず言語の仕様かもしれないが本質じゃないのでとりあえず保留(なんとなく整数値をboolに変換して0,1を返してる感じだった)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?