蓝桥杯 1560: [蓝桥杯][算法提高VIP]计算器 Easy only once *电子管二进制问题(利用进制进行分类)

基本思想:

两种方法:

1.进行变换情况的枚举,构成9*9矩阵,麻烦且凌乱;

2.直接再数位显示上进行标记,利用二进制来定类,对比不同的位数即可;

进行显现管标记,然后给出每个数字的7位二进制数串; 

关键点:

主要是这种标记分类取异或的思想,再很多分类问题中也可使用,类似于以前学习过的多标签思维;

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;

vector<string>vec = {
    "0111111",
    "0000110",
    "1011011",
    "1001111",
    "1100110",
    "1101101",
    "1111101",
    "0000111",
    "1111111",
    "1101111"
};


int chargment(int a, int b) {
    string m = vec[a];
    string n = vec[b];
    int cnt = 0;
    for (int i = 0; i < m.size(); i++) {
        if (m[i] != n[i])
            cnt++;
    }
    return cnt;
}

int main(){
    int cnt = 0;
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < a.size(); i++) {
        cnt += chargment(a[i] - '0', b[i] - '0');
    }
    cout << cnt;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/songlinxuan/p/12291415.html