zoukankan      html  css  js  c++  java
  • F. Binary String Reconstruction

    For some binary string ss (i.e. each character sisi is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length 22 were written. For each pair (substring of length 22), the number of '1' (ones) in it was calculated.

    You are given three numbers:

    • n0n0 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 00;
    • n1n1 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 11;
    • n2n2 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 22.

    For example, for the string s=s="1110011110", the following substrings would be written: "11", "11", "10", "00", "01", "11", "11", "11", "10". Thus, n0=1n0=1, n1=3n1=3, n2=5n2=5.

    Your task is to restore any suitable binary string ss from the given values n0,n1,n2n0,n1,n2. It is guaranteed that at least one of the numbers n0,n1,n2n0,n1,n2 is greater than 00. Also, it is guaranteed that a solution exists.

    Input

    The first line contains an integer tt (1t10001≤t≤1000) — the number of test cases in the input. Then test cases follow.

    Each test case consists of one line which contains three integers n0,n1,n2n0,n1,n2 (0n0,n1,n21000≤n0,n1,n2≤100; n0+n1+n2>0n0+n1+n2>0). It is guaranteed that the answer for given n0,n1,n2n0,n1,n2 exists.

    Output

    Print tt lines. Each of the lines should contain a binary string corresponding to a test case. If there are several possible solutions, print any of them.

    Example
    input
    Copy
    7
    1 3 5
    1 1 1
    3 9 3
    0 1 0
    3 1 2
    0 0 3
    2 0 0
    
    output
    Copy
    1110011110
    0011
    0110001100101011
    10
    0000111
    1111
    000
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    //#include <unordered_map>
    //#include <bits/stdc++.h>
    //#include <xfunctional>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define pb              push_back
    #define mk              make_pair
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979;
    const int mod = 998244353;
    const int N = 2e5+5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m%n);
    }
    ll lcm(ll m, ll n)
    {
        return m*n / gcd(m, n);
    }
    
    int main()
    {
        int T;
        cin >> T;
        while (T--)
        {
            string s="";
            int a, b, c;
            cin >> a >> b >> c;
            if (a > 0)
            {
                rep(i, 0, a)
                {
                    s += '0';
                }
            }
            if (c > 0)
            {
                rep(i, 0, c)
                {
                    s += '1';
                }
            }
            int fg;
            if (a==0 && c==0)
            {
                b++;
                fg = 1;
            }
            if(a>0 && c>0)
                b--,fg = 1;
            if (a == 0 && c > 0)
                fg = 1;
            if (a > 0 && c == 0)
                fg = 0;
            rep(i, 1, b)
            {
                if (fg)
                {
                    s += '0';
                    fg = 0;
                }
                else
                {
                    s += '1';
                    fg = 1;
                }
            }
            cout << s << endl;
        }
        return 0;
    }
  • 相关阅读:
    CSS标题线(删除线贯穿线效果)实现之一二
    sublime修改快捷键样式
    使用css鼠标移动到图片放大效果
    js判断苹果安卓操作系统,js更换css
    清除缓存
    mui下拉上拉(明一)
    mui下拉刷新上拉加载
    Cypher学习笔记
    github上计算String相似度好的项目
    代码重构
  • 原文地址:https://www.cnblogs.com/dealer/p/12894152.html
Copyright © 2011-2022 走看看