Codeforces Round #806 (Div. 4)(7/7)

Problem - A - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

void Solve() {
    string s;
    cin >> s;
    if ((s[0] == 'Y' || s[0] == 'y') && (s[1] == 'e' || s[1] == 'E') && (s[2] == 's' || s[2] == 'S')) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}

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

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

Problem - B - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

void Solve() {
    int len;
    cin >> len;
    string s;
    cin >> s;
    int ans = 0;
    vector<bool> vis(26, 0);
    for (int i = 0; i < len; i++) {
        if (!vis[s[i] - 'A']) {
            vis[s[i] - 'A'] = true;
            ans += 2;
        }
        else {
            ans++;
        }
    }
    cout << ans << '\n';
}

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

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

Problem - C - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

void Solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int j = 0; j < n; j++) {
        int m;
        string s;
        cin >> m >> s;
        for (int i = 0; i < m; i++) {
            if (s[i] == 'D') {
                a[j] = (a[j] + 1) % 10;
            }
            else {
                a[j] = (a[j] + 9) % 10;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << a[i] << " \n"[i == n - 1];
    }
}

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

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

Problem - D - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

void Solve() {
    int n;
    cin >> n;
    vector<string> a(n);
    map<string, int> mp1, mp2;
    string ans = "";
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp1[a[i]] = 1;
        string two = a[i] + a[i];
        mp2[two] = 1;
    }
    for (int i = 0; i < n; i++) {
        string s1 = "", s2 = "";
        int len = a[i].size();
        bool ok = false;
        if (mp2[a[i]] == 1) {
            ok = true;
        }
        for (int j = 0; j < len - 1; j++) {
            s1 = a[i].substr(0, j + 1);
            s2 = a[i].substr(j + 1, len - 1);
            if (mp1[s1] == 1 && mp1[s2] == 1) {
                ok = true;
            }
        }
        if (ok) {
            ans += '1';
        }
        else {
            ans += '0';
        }
    }
    cout << ans << '\n';
}

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

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

Problem - E - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

void Solve() {
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    LL ans = 0;
    if (n & 1) {
        for (int i = 0; i < n / 2; i++) {
            for (int j = 0; j < n / 2; j++) {
                int cnt0 = 0, cnt1 = 0;
                if (a[i][j] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[j][n - i - 1] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[n - i - 1][n - j - 1] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[n - j - 1][i] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                ans += min(4 - cnt0, 4 - cnt1);
            }
        }
        for (int j = 0; j < n / 2; j++) {
            int cnt0 = 0, cnt1 = 0;
                if (a[n / 2][j] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[j][n - n / 2 - 1] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[n - n / 2 - 1][n - j - 1] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[n - j - 1][n / 2] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                ans += min(4 - cnt0, 4 - cnt1);
        }
    }
    else {
        for (int i = 0; i < n / 2; i++) {
            for (int j = 0; j < n / 2; j++) {
                int cnt0 = 0, cnt1 = 0;
                if (a[i][j] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[j][n - i - 1] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[n - i - 1][n - j - 1] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                if (a[n - j - 1][i] == '0') {
                    cnt0++;
                }
                else {
                    cnt1++;
                }
                ans += min(4 - cnt0, 4 - cnt1);
            }
        }
    }
    cout << ans << '\n';
}

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

    int T;
    cin >> T;
    while (T--) {
         Solve();
    }

    return 0;
}

Problem - F - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL a[200010], tree[200010];
int n;
int lowbit(int x) {
    return x & -x;
}
LL getsum(int x) {
    LL res = 0;
    for (int i = x; i > 0; i -= lowbit(i)) {
        res += tree[i];
    }
    return res;
}
void update(int x, int v) {
    for (int i = x; i <= n; i += lowbit(i)) {
        tree[i] += v;
    }
}
void Solve() {
    cin >> n;
    LL ans = 0;
    memset(tree, 0, sizeof(tree));
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; i--) {
        if (i > a[i]) {
            ans += getsum(n) - getsum(i + 1);
            update(a[i] + 1, 1);
        }
    }
    cout << ans << '\n';
}

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

    int T;
    cin >> T;
    while (T--) {
         Solve();
    }

    return 0;
}

Problem - G - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

void Solve() {
    int n;
    LL k;
    cin >> n >> k;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    LL ans = -0x3f3f3f3f;
    LL sum = 0;
    for (int i = 0; i < n; i++) {
        LL s = 0;
        for (int j = 0; j <= 32; j++) {
            if (i + j > n - 1) {
                break;
            }
            s += a[i + j] >> (j + 1);
        }
        ans = max(ans, sum + s);
        sum += a[i] - k;
    }
    cout << max(ans, sum) << '\n';
}

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

    int T;
    cin >> T;
    while (T--) {
         Solve();
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值