首页 > 其他分享 >ABC314

ABC314

时间:2023-08-12 23:22:54浏览次数:41  
标签:ps int ABC314 cin vector ans rep

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;
}

标签:ps,int,ABC314,cin,vector,ans,rep
From: https://www.cnblogs.com/Melville/p/17625825.html

相关文章