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

For example, for the string "01010" there are four indices i such that 1≤i<n and si≠si+1 (i=1,2,3,4). For the string "111001" there are two such indices i (i=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 a, b and x (1≤a,b≤100,1≤x<a+b). Output
Print only one string s, where s is any binary string satisfying conditions described above. It is guaranteed that the answer always exists. Examples
Input
2 2 1
Output
1100
Input
3 3 3
Output
101100
Input
5 3 6
Output
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.

【代码】:

#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const ll LNF = 1e18;
const int N = 1e3 + 20;
const int maxm = 1e6 + 10;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/*
对于x,我们很容易就可以想到先输出x/2对0和1(n对0和1交错出现可以提供2*n-1个符合题意的ai)
然后将剩余的0和剩余的1连续输出(提供1个符合条件的ai,这样就刚好是x个符合条件的ai了,
需要注意的是,我们要优先将个数多的放在前面,
例如,有10个1,5个0的话,我们先输出x/2个“10”,否则,输出x/2个“01”)。
*/
int main()
{
int a,b,x;
while(cin>>a>>b>>x)
{
if(x%2==0)//5 2 4
{
if(a>b)
{
for(int i=0;i<x/2;i++)
cout<<"01";
cout<<string(b-x/2,'1');
cout<<string(a-x/2,'0');
}
else{
for(int i=0;i<x/2;i++)
cout<<"10";
cout<<string(a-x/2,'0');
cout<<string(b-x/2,'1');
}
}
else
{
if(a>b)//5 2 3
{
for(int i=0;i<x/2;i++)
cout<<"01";
cout<<string(a-x/2,'0');
cout<<string(b-x/2,'1');
}
else
{
for(int i=0;i<x/2;i++)
cout<<"10";
cout<<string(b-x/2,'1');
cout<<string(a-x/2,'0');
}
}
cout<<endl;
}
}

CF 1003B Binary String Constructing 【构造/找规律/分类讨论】的更多相关文章

  1. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

  2. UVALive - 6577 Binary Tree 递推+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48421 Binary Tree Time Limit: 3000MS 问题描述 Binary Tree is ...

  3. Full Binary Tree(二叉树找规律)

    Description In computer science, a binary tree is a tree data structure in which each node has at mo ...

  4. POJ 2499 Binary Tree(二叉树,找规律)

    题意:给一个这样的二叉树,每个节点用一对数(a,b)表示,根节点为(1,1).设父亲为(a,b),左儿子(a+b,b),右儿子(a,a+b). 给几组数据,(i,j),求从根节点到(i,j)节点需要向 ...

  5. Educational Codeforces Round 94 (Rated for Div. 2) C. Binary String Reconstruction (构造)

    题意:给你一个字符串\(s\),原字符串为\(w\),如果\(i>x\)且\(w_{i-x}=1\),那么\(s_{i}=1\),如果\(i+x\le n\)且\(w_{i+x}=1\),那么\ ...

  6. 【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor

    题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...

  7. HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)

    Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. CF 1107 E. Vasya and Binary String

    E. Vasya and Binary String 链接 分析: 对于长度为x的一段序列,我们可以dp出消除的过程的最优方案,背包即可. 然后区间dp,可以先合并完所有的点,即没相同的一段区间合并为 ...

  9. CodeForces - 1003-B-Binary String Constructing (规律+模拟)

    You are given three integers aa, bb and xx. Your task is to construct a binary string ssof length n= ...

随机推荐

  1. 【bzoj4976】宝石镶嵌 乱搞+dp

    题目描述 从$n$个数中选出$n-k$个,使得它们的二进制或(or)最大.输出这个值. 输入 第一行包含两个正整数$n,k(2\le n\le 100000,1\le k\le 100,k<n) ...

  2. [POI2011]Lightning Conductor

    题面在这里 description 已知一个长度为\(n\)的序列\(a_1,a_2,...,a_n\). 对于每个\(1\le i\le n\),找到最小的非负整数\(p\), 满足对于任意的\(1 ...

  3. 如何实现加载DOM时执行js代码

    有一些功能需求,需要在DOM载入时马上执行一些函数,但又不愿意仅为了这一个需求而引入整个JQuery库,于是就把jQuery的方法提取出来,单独使用了. 大家可以使用windows.onload事件, ...

  4. 使用JMeter进行一次简单的带json数据的post请求测试

    使用JMeter进行一次简单的带json数据的post请求测试 原文:https://www.cnblogs.com/summer-mm/p/7717812.html 1.启动jmeter:在bin下 ...

  5. GROUP_CONCAT(expr)

    This function returns a string result with the concatenated non-NULL values from a group. It returns ...

  6. HDU4280:Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. java程序在centos7里面开机自启动

    1.我们先来个简单的start,status,stop程序: [root@localhost ~]# cat /home/tomcat/jarservice.sh #!/bin/bashCU_PID= ...

  8. React 获取 url 参数 —— this.props.match

    在 react 组件的  componentDidMount 方法中打印一下 this.props,在浏览器控制台中查看输出如下: 其中页面的 url 信息全都包含在 match 字段中,以地址 lo ...

  9. eclipse读取含有extjs的项目文件时卡死

    打开项目的.project文件,将<buildCommand>                        <name>org.eclipse.wst.jsdt.core.j ...

  10. django中管理程序1

    为了解决启动关闭程序方便,在django中启动结束任务的问题. urls.py ################DJANGO start kill job####################### ...