Codeforces Round 862 (Div. 2)(CF1805) A-C题题解

发布时间 2023-04-03 00:44:36作者: SunnyYuan

CF1805A

#include <bits/stdc++.h>

#define debug(x) cout << "The variable \"" << #x << "\" of the \"" << __FUNCTION__ << "\" function in line " << __LINE__ << " of \"" << __FILE__ << "\" is " << x << endl;

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& x : a) cin >> x;
    int sum = 0;
    for (int& x : a) sum ^= x;
    if (n & 1) {
        cout << sum << '\n';
    }
    else {
        if (sum) cout << "-1\n";
        else cout << "0\n";
    }
}

int main() {
    #ifdef DEBUG
    clock_t st, ed;
    cout << "===================START===================" << endl;
    st = clock();
    #endif

    // #ifndef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // #endif

    int T;
    cin >> T;
    while (T--) solve();

    #ifdef DEBUG
    ed = clock();
    cout << "====================END====================" << endl;
    cout << "Time:" << (ed - st) * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
    return 0;
}

CF1805B

#include <bits/stdc++.h>

#define debug(x) cout << "The variable \"" << #x << "\" of the \"" << __FUNCTION__ << "\" function in line " << __LINE__ << " of \"" << __FILE__ << "\" is " << x << endl;

using namespace std;

void solve() {
    int len;
    string a;
    cin >> len >> a;
    int p = 0;
    for (int i = 0; i < len; i++) {
        if (a[i] <= a[p]) {
            p = i;
        }
    }
    // debug(p);
    cout << a[p];
    for (int i = 0; i < len; i++) {
        if (i == p) continue;
        cout << a[i];
    }
    cout << '\n';
}

int main() {
    #ifdef DEBUG
    clock_t st, ed;
    cout << "===================START===================" << endl;
    st = clock();
    #endif

    // #ifndef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // #endif

    int T;
    cin >> T;
    while (T--) solve();

    #ifdef DEBUG
    ed = clock();
    cout << "====================END====================" << endl;
    cout << "Time:" << (ed - st) * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
    return 0;
}

CF1805C

#include <bits/stdc++.h>

#define int long long

#define debug(x) cout << "The variable \"" << #x << "\" of the \"" << __FUNCTION__ << "\" function in line " << __LINE__ << " of \"" << __FILE__ << "\" is " << x << endl;

using namespace std;

const int N = 100010;

int n, m;
int k[N];

int find1(int b, int ac_4) {
    int p = upper_bound(k + 1, k + n + 1, b) - k;
    int l = 0, r = p;
    while (l + 1 < r) {
        int mid = (l + r) / 2;
        if ((b - k[mid]) * (b - k[mid]) >= ac_4) l = mid;
        else r = mid;
    }
    int res = r;
    if (res >= p || res < 1 || (b - k[res]) * (b - k[res]) >= ac_4) return -1;
    return res;
}

int find2(int b, int ac_4) {
    int p = upper_bound(k + 1, k + n + 1, b) - k;
    if (p > n) return -1;
    int l = p - 1, r = n + 1;
    while (l + 1 < r) {
        int mid = (l + r) / 2;
        if ((k[mid] - b) * (k[mid] - b) < ac_4) l = mid;
        else r = mid;
    }
    int res = l;
    if (res < p || res > n || (b - k[res]) * (b - k[res]) >= ac_4) return -1;
    return res;
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> k[i];
    }
    sort(k + 1, k + n + 1);

    for (int i = 1; i <= m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        int f1 = find1(y, 4 * x * z);
        int f2 = find2(y, 4 * x * z);
        if (f1 == -1 && f2 == -1) {
            cout << "NO\n";
        }
        else {
            cout << "YES\n";
            if (f1 == -1) cout << k[f2] << '\n';
            else cout << k[f1] << '\n';
        }
    }
    cout << '\n';
}

signed main() {
    #ifdef DEBUG
    clock_t st, ed;
    cout << "===================START===================" << endl;
    st = clock();
    #endif

    // #ifndef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // #endif

    int T;
    cin >> T;
    while (T--) solve();

    #ifdef DEBUG
    ed = clock();
    cout << "====================END====================" << endl;
    cout << "Time:" << (ed - st) * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
    return 0;
}