2 条题解

  • 0
    @ 2024-4-13 0:12:18

    模拟即可

    题目参考出处 霓虹【算法赛】 - 蓝桥云课 (lanqiao.cn)

    双倍经验了算是,将原题的输入读入改为循环枚举当前数和下一个数,将这两数的字符串形式作为题目的输入处理即可

    #include <bits/stdc++.h>
    
    using namespace std;
    
    using i64 [[maybe_unused]] = long long;
    template<typename T, class comparer = greater<T>>
    using heap = priority_queue<T, vector<T>, comparer>;
    const char &ln = '\n';
    #define parse static_cast
    
    signed main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int arr[10][10]{
                {0, 4, 3, 3, 4, 3, 2, 3, 1, 2},
                {4, 0, 5, 3, 2, 5, 6, 1, 5, 4},
                {3, 5, 0, 2, 5, 4, 3, 4, 2, 3},
                {3, 3, 2, 0, 3, 2, 3, 2, 2, 1},
                {4, 2, 5, 3, 0, 3, 4, 3, 3, 2},
                {3, 5, 4, 2, 3, 0, 1, 4, 2, 1},
                {2, 6, 3, 3, 4, 1, 0, 5, 1, 2},
                {3, 1, 4, 2, 3, 4, 5, 0, 4, 3},
                {1, 5, 2, 2, 3, 2, 1, 4, 0, 1},
                {2, 4, 3, 1, 2, 1, 2, 3, 1, 0}
        };
        string a, b;
        int ans = 0;
        for(int i = 1000; i < 2024; ++i) {
          a = to_string(i), b = to_string(i + 1);
        for(int i = 0; i < a.length(); ++i) {
            int x = a[i] ^ '0', y = b[i] ^ '0';
            ans += arr[x][y];
        }
        }
        cout << ans;
        return 0;
    }
    
    • -2
      @ 2024-4-11 21:39:52
      # '10':4  表示1到0的转变要4次
      d={'10':4,'21':5,'32':2,'43':3,'54':3,'65':1,'76':5,'87':4,'98':1,'09':2}
      c=0
      for i in range(1001,1011):
          i1=str(i-1)
          i=str(i)
          for _ in range(4):
              if i[_]!=i1[_]:
                  c+=d[i[_]+i1[_]]
      print(c)
      
      • 1

      信息

      ID
      996
      时间
      1000ms
      内存
      256MiB
      难度
      2
      标签
      递交数
      150
      已通过
      39
      上传者