1 条题解

  • 0
    @ 2025-10-19 15:15:04
    #include <bits/stdc++.h>
    using namespace std;
    #define rep(i, l, r) for (int i = l; i <= r; i++)
    #define int long long
    #define endl '\n'
    void solve() {
        int n,d; 
        cin >> n >> d; 
        while(n--){
            int x,ok = 0;  // ok:是否合法的标记
            cin >> x;  
            if(x >= 10 * d){
                cout << "YES" << '\n';
                continue;
            }
            while(x > 0){
                if(x % d == 0){
                    ok = 1;
                    cout << "YES" << '\n';
                    break;
                }
                x -= 10;
            }
            if(!ok) cout << "NO" << '\n';
        }
    }
    signed main() {
        ios::sync_with_stdio(0);
        cin.tie(0),cout.tie(0);
        int T = 1;
        cin >> T;
        while (T--)
            solve();
        return 0;
    }
    
    • @ 2025-10-19 15:39:08

      本题主要考查数学规律推导贪心策略的应用。多找些数看看什么哪些数合法。

    • @ 2025-10-19 15:39:23
      若d == 7
      易知下面是合法的数字 X
      7 17 27 37 47 57 67 70 71 72 73 74 75 76 77 78 79 87 97 ......
      我们再看看下面合法的数
      80 = 7 + 73
      81 = 7 + 74
      82 = 7 + 75
      83 = 7 + 76
      84 = 7 + 77
      85 = 7 + 78
      ......
      123 = 47 + 76
      124 = 47 + 77
      125 = 47 + 78
      ......
      1233 = 1157 + 76
      1234 = 1157 + 77
      1235 = 1157 + 78
      ......
      细心的你已经发现一些规律了
      故:(1)若 X >= 10 * d ,则一定可以 
      
      那么若 X < 10 * d 呢?
      我们通过举例观察发现:
      7 17 27 37 ... 可以
      14 24 34 54 ... 也可以
      14 = 7 + 7  = 7 * 1 + 7  = 7 * 2 + 10 * 0
      24 = 7 + 17 = 7 * 1 + 17 = 7 * 2 + 10 * 1
      34 = 7 + 27 = 7 * 1 + 27 = 7 * 2 + 10 * 2
      ......
      21 = 7 + 7 + 7  = 7 * 2 + 7  = 7 * 3 + 10 * 0
      31 = 7 + 7 + 17 = 7 * 2 + 17 = 7 * 3 + 10 * 1
      41 = 7 + 7 + 27 = 7 * 2 + 27 = 7 * 3 + 10 * 2
      51 = 7 + 7 + 37 = 7 * 2 + 37 = 7 * 3 + 10 * 3
      ......
      细心的你已经发现一些规律了
      故:(2)若 X < 10 * d 且 X == d * k1 + 10 * k2 (k1,k2 >= 0) 则一定可以
      
      则:(3)若都不能满足上述(1),(2),则该X不合法
      
    • @ 2025-10-19 15:43:10

      (x < 10d)时,循环中每次执行 (x -= 10),最多执行的次数是​常数次​:

      • d 的范围是 (1 <= d <= 9),因此 10d 最大为 90,即 x 最大不超过 89
      • 每次减 10,最多循环 8次。
      • 故代码不会超时。
  • 1

信息

ID
1147
时间
1000ms
内存
256MiB
难度
8
标签
递交数
72
已通过
11
上传者