link

A

#include "bits/stdc++.h"

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;

    cout << (s.find("99") != -1 ? "YES" : "NO") << '\n';

    return 0;
}

B

#include "bits/stdc++.h"

using namespace std;

void solve() {
    int n;
    string s;
    cin >> n >> s;

    cout << (int) *max_element(s.begin(), s.end()) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

C

#include "bits/stdc++.h"

using namespace std;

void solve() {
    int k;
    cin >> k;
    
    if (!k) {
        cout << "1\n";
        return;
    }
  
    string ans;
    while (k > 1) {
        ans += '8';
        k -= 2;
    }
    if (k > 0) {
        ans += '4';
    }
  
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

D

考虑第 个数字是奇数还是偶数。

#include "bits/stdc++.h"

using namespace std;

void solve() {
    int x, p;
    cin >> x >> p;
  
    int q = p / x, r = p % x;
    if (!r) {
        cout << 2 * q - 1 << '\n';
    } else {
        cout << 2 * (p - q) << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

E

倒着分析,考虑哪些情况是不得不变。

#include "bits/stdc++.h"

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    unordered_map<int, int> cnt, mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    int c = 1E9;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] <= i || a[i] >= c || cnt[a[i]] > 1 || mp.count(a[i])) {
            mp[a[i]] = 1, c = i + 1;
        } else {
            c = a[i];
        }
    }
    cout << mp.size() << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

F

考虑按高位到低位贪心,若到某一位时剩余数量不足以分给 个人,那么只给一部分人在该位进行分配,使得剩下的糖果恰好可以在后面的位进行完美分配。

#include "bits/stdc++.h"

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
  
    int ans = 0;
    for (int i = 30; i >= 0; i--) {
        int x = 1 << i;
        if (n / m >= x) {
            n -= x * m;
            ans |= x;
        }  else {
            if (n / m >= x - 1) {
                n -= (n - (x - 1) * m + x - 1) / x * x;            
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}