1003B - Binary String Constructing

B. Binary String Constructing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given three integers aabb and xx. Your task is to construct a binary string ss of length n=a+bn=a+b such that there are exactly aa zeroes, exactly bb ones and exactly xx indices ii (where 1i<n1≤i<n) such that sisi+1si≠si+1. It is guaranteed that the answer always exists.

For example, for the string "01010" there are four indices ii such that 1i<n1≤i<n and sisi+1si≠si+1 (i=1,2,3,4i=1,2,3,4). For the string "111001" there are two such indices ii (i=3,5i=3,5).

Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.

Input

The first line of the input contains three integers aabb and xx (1a,b100,1x<a+b)1≤a,b≤100,1≤x<a+b).

Output

Print only one string ss, where ss is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.

Examples
input
Copy
2 2 1
output
Copy
1100
input
Copy
3 3 3
output
Copy
101100
input
Copy
5 3 6
output
Copy
01010100
Note

All possible answers for the first example:

  • 1100;
  • 0011.

All possible answers for the second example:

  • 110100;
  • 101100;
  • 110010;
  • 100110;
  • 011001;
  • 001101;
  • 010011;
  • 001011.


题意:输入a,b,x,要构造出一个一个01串,有a个0,b个1,01或者10,有x个。

题解:构造  从不擅长构造,所以看别人思路,第二天做,不是比赛ac的...

c++:

#include<bits/stdc++.h>
using namespace std;
int a,b,x,c;
int main()
{
    cin>>a>>b>>x;
    if(a>=b)c=0;
    else c=1;
    while(x>1)
    {
        cout<<c;
        if(c) b--;
        else a--;
        c=1-c,x--;
    }
    if (c)
    {
        for(int i=0; i<b; i++)
            cout<<1;
        for(int j=0; j<a; j++)
            cout<<0;
    }
    else
    {
        for(int i=0; i<a; i++)
            cout<<0;
        for(int j=0; j<b; j++)
            cout<<1;
    }
    return 0;
}

python:

a,b,x=map(int,input().split())
s=""
if a>=b:c=0
else:c=1
while x>1:
    s+=str(c)
    if c==0:a-=1
    else:b-=1
    c=1-c;x-=1
if c==0:s+=a*"0"+b*"1"
else:s+=b*"1"+a*"0"



猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/80907778