AtCoder Beginner Contest 323

foolnine / 2024-08-06 / 原文

C - World Tour Finals

https://atcoder.jp/contests/abc323/tasks/abc323_c
排序加暴力即可。因为读题错误卡了十几分钟,很不应该,以后要认真读题后再做题

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

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

    int n, m;
    cin >> n >> m;

    vector<long long> a(m);
    vector<pair<long long, int>> p(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        p[i] = {-a[i], i};
    }
    sort(p.begin(), p.end());

    vector<string> s(n);
    vector<long long> sum(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        for (int j = 0; j < m; j++) {
            if (s[i][j] == 'o') {
                sum[i] += a[j];
            }
        }
    }

    long long ssum = 0;
    for (int i = 0; i < n; i++) {
        sum[i] += i + 1;
        ssum = max(ssum, sum[i]);
    }

    for (int i = 0; i < n; i++) {
        long long need = ssum - sum[i];
        int cnt = 0;
        for (int j = 0; j < m; j++) {
            if (need <= 0) break;
            int k = p[j].second;
            if (s[i][k] == 'x') {
                need += p[j].first;
                cnt++;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}

D - Merge Slimes

https://atcoder.jp/contests/abc323/tasks/abc323_d
从小到大合并就ok了,简单题

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

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

    int n;
    cin >> n;

    map<long long, long long> mp;
    for (int i = 0; i < n; i++) {
        long long x, y;
        cin >> x >> y;
        mp.insert({x, y});
    }

    long long ans = 0;
    while (!mp.empty()) {
        auto it = mp.begin();
        long long x = it->first * 2, y = it->second / 2;
        if (it->second % 2 == 1) {
            ans++;
        }
        mp.erase(it);
        if (y > 0) {
            mp[x] += y;
        }
    }
    cout << ans << endl;

    return 0;
}

E - Playlist

https://atcoder.jp/contests/abc323/tasks/abc323_e
一眼不会,滚去做F

F - Push and Carry

https://atcoder.jp/contests/abc323/tasks/abc323_f
不会E所以来做F了,模拟。只需要有耐心就能够写出来,具体见代码

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

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

    const int n = 3;
    vector<long long> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }

    long long ans = llabs(x[1] - x[2]) + llabs(y[1] - y[2]);
    if (x[1] == x[2]) {
        if (y[1] > y[2]) {
            if (x[0] == x[1] && y[0] < y[1]) {
                ans += 2;
            }
            ans += llabs(x[0] - x[1]) + llabs(y[0] - y[1] - 1);
        } else {
            if (x[0] == x[1] && y[0] > y[1]) {
                ans += 2;
            }
            ans += llabs(x[0] - x[1]) + llabs(y[0] - y[1] + 1);
        }
    } else if (y[1] == y[2]) {
        if (x[1] < x[2]) {
            if (y[0] == y[1] && x[0] > x[1]) {
                ans += 2;
            }
            ans += llabs(y[0] - y[1]) + llabs(x[0] - (x[1] - 1));
        } else {
            if (y[0] == y[1] && x[0] < x[1]) {
                ans += 2;
            }
            ans += llabs(y[0] - y[1]) + llabs(x[0] - (x[1] + 1));
        }
    } else {
        ans += 2;

        long long ax1, ay1;
        long long len1 = 0;
        if (x[1] < x[2]) {
            ax1 = x[1] - 1;
            ay1 = y[1];

            if (y[0] == ay1 && x[0] > x[1]) {
                len1 += 2;
            }
            len1 += llabs(x[0] - ax1) + llabs(y[0] - ay1);
        } else {
            ax1 = x[1] + 1;
            ay1 = y[1];

            if (y[0] == ay1 && x[0] < x[1]) {
                len1 += 2;
            }
            len1 += llabs(x[0] - ax1) + llabs(y[0] - ay1);
        }

        long long ax2, ay2;
        long long len2 = 0;
        if (y[1] < y[2]) {
            ax2 = x[1];
            ay2 = y[1] - 1;

            if (x[0] == ax1 && y[0] > y[1]) {
                len2 += 2;
            }
            len2 += llabs(x[0] - ax2) + llabs(y[0] - ay2);
        } else {
            ax2 = x[1];
            ay2 = y[1] + 1;

            if (x[0] == ax1 && y[0] < y[1]) {
                len2 += 2;
            }
            len2 += llabs(x[0] - ax2) + llabs(y[0] - ay2);
        }
        ans += min(len1, len2);
    }
    cout << ans << endl;

    return 0;
}

G - Inversion of Tree

https://atcoder.jp/contests/abc323/tasks/abc323_g
G这类题遇到都是不会的,无从下手