2025-11-26

CF

构造(1300)

Problem - 1867C - Codeforces(交互)

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

void solve()
{
    int n;
    cin >> n;
    for (int i = 0; i < n;i++){
        cin >> a[i];
    }
    int i = 0;
    while(a[i]==i&&i<n){
        i++;
    }
    cout << i << endl;
    int y;
    while(1){
        cin >> y;
        if(y==-1||y==-2)
            break;
        cout << y << endl;
    }
}

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

Problem - 1839C - Codeforces

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

void solve()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n;i++){
        cin >> a[i];
    }
    if(a[n]==1){
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
    int cnt = 0;
    for (int i = n; i >= 1;i--){
        if(a[i]==0){
            cout << "0 ";
        }else{
            cnt++;
            if(a[i-1]==0){
                cout << cnt << " ";
                cnt = 0;
            }else{
                cout << "0 ";
            }
        }
    }
    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-26 21:40  Seren_blingbling  阅读(4)  评论(0)    收藏  举报