Codeforces Round #640 (Div. 4) F. Binary String Reconstruction(構造)

題目鏈接

思路:全是0和1的時候特判,然後構造字符串先輸出n0個0然後對n2分奇偶情況輸出。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false)
#define space putchar(' ')
#define enter putchar('\n')
typedef pair<int,int> PII;
const int mod=1e4+7;
const int N=2e5+10;
const int inf=0x7f7f7f7f;


ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}

template <class T>
void read(T &x)
{
    char c;
    bool op = 0;
    while(c = getchar(), c < '0' || c > '9')
        if(c == '-')
            op = 1;
    x = c - '0';
    while(c = getchar(), c >= '0' && c <= '9')
        x = x * 10 + c - '0';
    if(op)
        x = -x;
}
template <class T>
void write(T x)
{
    if(x < 0)
        x = -x, putchar('-');
    if(x >= 10)
        write(x / 10);
    putchar('0' + x % 10);
}


int main()
{
    SIS;
    int t;
    cin>>t;

    while(t--)
    {
        int n1,n2,n3;
        cin>>n1>>n2>>n3;
        if(n2==0&&n3==0)
        {
            for(int i=0; i<=n1; i++)
                cout<<0;
            cout<<endl;
            continue;
        }
        else if(n1==0&&n2==0)
        {
            for(int i=0; i<=n3; i++)
                cout<<1;
            cout<<endl;
            continue;
        }
        else if(n1==0&&n3==0)
        {
            for(int i=1; i<=n2+1; i++)
            {
                if(i%2!=0)
                    cout<<0;
                else
                    cout<<1;
            }
            cout<<endl;
            continue;
        }
        else
        {
            for(int i=1; i<=n1; i++)
                cout<<0;
            if(n2%2==0)
            {
                for(int i=1; i<=n2; i++)
                {
                    if(i%2!=0)
                        cout<<0;
                    else
                        cout<<1;
                }
                for(int i=1; i<=n3; i++)
                    cout<<1;
                cout<<0<<endl;
                continue;
            }
            for(int i=1; i<=n2+1; i++)
            {
                if(i%2!=0)
                    cout<<0;
                else
                    cout<<1;
            }


            if((n2+1)%2!=0&&n3!=0)
                cout<<1;
            for(int i=1; i<=n3; i++)
                cout<<1;
            cout<<endl;

        }



    }



    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章