Codeforces Round #829 (Div. 2)1754

酶和ATP 2022年11月05日 524次浏览

A. Technical Support


Note :One or several.

// #pragma GCC optimize(3)
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt1 = 0, cnt2 = 0;
    for (auto a : s) {
        if (a == 'Q') {
            cnt1++;
        } else {
            cnt2 = min(cnt2 + 1, cnt1);
        }
    }
    if (cnt1 <= cnt2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

B. Kevin and Permutation


巧妙,但感觉做过一道LC的题目类似,找到了!
https://leetcode.cn/problems/beautiful-arrangement-ii/

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

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

    int cnt = n / 2 + 1;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1)
            cout << cnt + (i / 2) << ' ';
        else
            cout << (i / 2) << ' ';
    }
    cout << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}