ABC314

V_Melville精進録 / 2023-08-13 / 原文

T1:3.14

模拟

代码实现
s = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'
n = int(input())
ans = s[0:n+2]
print(ans)

T2:Roulette

模拟

代码实现
#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<int> c(n);
    vector<vector<int>> a(n);
    rep(i, n) {
        cin >> c[i];
        a[i] = vector<int>(c[i]);
        rep(j, c[i]) cin >> a[i][j];
    }
    
    int x;
    cin >> x;
    
    vector<bool> bet(n);
    rep(i, n) {
        bet[i] = any_of(a[i].begin(), a[i].end(), [&](int e) { return e == x;});
    }
    
    int cmin = 37;
    rep(i, n) {
        if (bet[i]) cmin = min(cmin, c[i]);
    }
    
    vector<int> ans;
    rep(i, n) {
        if (bet[i] and c[i] == cmin) ans.push_back(i+1);
    }
    
    cout << ans.size() << '\n';
    for (int i : ans) cout << i << ' ';
    
    return 0;
}

T3:Rotate Colored Subsequence

模拟
可以预处理一下每种颜色的位置

代码实现
#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;
    string s;
    cin >> s;
    vector<int> c(n);
    rep(i, n) cin >> c[i];
    
    vector<vector<int>> ps(m);
    rep(i, n) ps[c[i]-1].push_back(i);
    
    string ans = s;
    rep(i, m) {
        int l = ps[i].size();
        rep(j, l) {
            ans[ps[i][(j+1)%l]] = s[ps[i][j]];
        }
    }
    
    cout << ans << '\n';
    
    return 0;
}

T4:LOWER

显然只有最后一个大小写颠倒的操作有效,那么我们只需找到这个时刻,按顺序在此时刻之前的操作 \(1\),然后在此时刻做大小写颠倒操作,在此操作之后继续执行操作 \(1\)

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

using namespace std;

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    
    vector<int> lt(n);
    int last = -1, type = 2;
    rep(qi, q) {
        int t, x; char c;
        cin >> t >> x >> c;
        --x;
        if (t == 1) {
            s[x] = c;
            lt[x] = qi;
        }
        else {
            last = qi;
            type = t;
        }
    }
    
    rep(i, n) {
        if (lt[i] < last) {
            if (type == 2) s[i] = tolower(s[i]);
            else s[i] = toupper(s[i]);
        }
    }
    
    cout << s << '\n';
    
    return 0;
}