2025-11-24

CF

构造(1300)

Problem - 1889A - Codeforces

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;

void add(string &s,int x){//在第 x个字符前加入
    s = s.substr(0, x) + "01" +s.substr(x);
}

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> cnt(2);
    for (int i = 0; i < n;i++){
        cnt[s[i] - '0']++;
    }
    if(cnt[0]!=cnt[1]){
        cout << -1 << endl;
        return;
    }
    vector<int> a;
    for (int i = 0; i < s.size();i++){
        int t = s.size() - i - 1;
        if(s[i]!=s[t])
            continue;
        if(s[i]=='0'){
            add(s, t + 1);
            a.push_back(t + 1);
        }
        else{
            add(s, i);
            a.push_back(i);
        }
        if(a.size()>300)
            break;
    }
    if(a.size()>300){
        cout << -1 << endl;
        return;
    }
    cout << a.size() << endl;
    for (int i = 0; i < a.size();i++){
        cout << a[i] << " ";
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

Problem - 1882B - Codeforces(bitset)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=55;
bitset<N> s[N], U;

void solve()
{
    int n;
    cin >> n;
    U.reset();//清零
    for (int i = 1; i <= n;i++){
        s[i].reset();
    }
    for (int i = 1; i <= n;i++){
        int k;
        cin >> k;
        for (int j = 1; j <= k;j++){
            int x;
            cin >> x;
            s[i][x] = 1;
        }
        U |= s[i];
    }
    int ans = 0;
    for (int i = 1; i <= 50;i++){
        if(U[i]==0)
            continue;
        bitset<N> now;
        for (int j = 1; j <= n;j++){//遍历每个集合
            if(s[j][i]==0)
                now |= s[j];
        }
        ans = max(ans, (int)now.count());
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

Problem - 1868A - Codeforces

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;

void solve()
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < min(m - 1, n);i++){
        for (int j = 0; j < m;j++){
            a[i][(i + j) % m] = j;
        }
    }
    for (int i = m - 1; i < n;i++){
        for (int j = 0; j < m;j++){
            a[i][j] = j;
        }
    }
    if (n<m){
        cout << n + 1 << endl;
    }else if(m==1){
        cout << 0 << endl;
    }
    else{
        cout << m << endl;
    }
    for (int i = 0; i < n;i++){
        for (int j = 0; j < m;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}
posted @ 2025-11-24 20:08  Seren_blingbling  阅读(4)  评论(0)    收藏  举报