首页 > 其他分享 >ABC323

ABC323

时间:2023-10-07 23:23:39浏览次数:31  
标签:int rep cin vector ABC323 mp ans

T1:Weak Beats

模拟

代码实现
s = input()
for i in range(1, len(s), 2):
    if s[i] == '1':
        exit(print('No'))
print('Yes')

T2:Round-Robin Tournament

模拟

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    
    vector<int> w(n);
    rep(i, n) {
        rep(j, n) if (s[i][j] == 'o') w[i]++;
    }
    
    vector<int> ans(n);
    rep(i, n) ans[i] = i;
    sort(ans.begin(), ans.end(), [&](int a, int b) {
        if (w[a] == w[b]) return a < b;
        return w[a] > w[b];
    });
    
    rep(i, n) cout << ans[i]+1 << ' ';
    
    return 0;
}

T3:World Tour Finals

模拟

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    
    vector<int> p(n);
    rep(i, n) {
        p[i] = i+1;
        rep(j, m) {
            if (s[i][j] == 'o') p[i] += a[j];
        }
    }
    int mx = *max_element(p.begin(), p.end());
    
    rep(i, n) {
        vector<int> r;
        rep(j, m) if (s[i][j] == 'x') r.push_back(a[j]);
        sort(r.begin(), r.end());
        int ans = 0;
        while (p[i] < mx) {
            p[i] += r.back();
            r.pop_back();
            ans++;
        }
        cout << ans << '\n';
    }
    
    return 0;
}

T4:Merge Slimes

每次合并最小的数,用 map 来维护数字的个数

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    
    map<ll, ll> mp;
    rep(i, n) {
        int s, c;
        cin >> s >> c;
        mp[s] = c;
    }
    
    int ans = 0;
    while (mp.size()) {
        auto [s, c] = *mp.begin();
        mp.erase(mp.begin());
        ans += c%2;
        c /= 2;
        if (c) mp[s*2] += c;
    }
    
    cout << ans << '\n';
    
    return 0;
}

标签:int,rep,cin,vector,ABC323,mp,ans
From: https://www.cnblogs.com/Melville/p/17747731.html

相关文章