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. oracle补充

    索引 索引是若干数据行的关键字的列表,查询数据时,通过索引中的关键字可以快速定位到要访问的记录所在的数据块,从而大大减少读取数据的I/O次数,因此可以显著的提高性能 创建索引的SQL 把下面表中的na ...

  2. 【bzoj3262】陌上花开 CDQ分治+树状数组

    题目描述 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当且仅当Sa&g ...

  3. BZOJ1857 [Scoi2010]传送带 【三分法】

    题目链接 BZOJ1857 题解 画画图就发现实际上是在\(AB\)上和\(CD\)上分别选两个点\(E\),\(F\),使得\(t_{AE} + t_{EF} + t_{FD}\)最小 然后猜想到当 ...

  4. CF762D Maximum Path

    题目戳这里. 首先明确一点,数字最多往左走一次,走两次肯定是不可能的(因为只有\(3\)行). 然后我们用\(f_{i,j}\)表示前\(i\)行,第\(i\)行状态为\(j\)的最优解.(\(j\) ...

  5. html初探

    HTML HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏 ...

  6. codevs 3305 水果姐逛水果街Ⅱ&&codevs3006

    题目描述 Description 水果姐第二天心情也很不错,又来逛水果街. 突然,cgh又出现了.cgh施展了魔法,水果街变成了树结构(店与店之间只有一条唯一的路径). 同样还是n家水果店,编号为1~ ...

  7. JGroups 初探

    最近研究 JAVA 集群技术,看到 jgroups 这个框架,网上有些例子,非常简单.可以参考其官方网址:http://www.jgroups.org/manual/index.html按捺不住,自己 ...

  8. 文本区 JTextArea 的使用

    文本区JTextArea是对多行文本进行编辑的组件,用空字符来控制文本的格式.eg:"\n"为换行,"\t"为插入一个Tab字符. 文本去JTextArea的常 ...

  9. mobius反演讲解

    mobius反演的基本形式为,假设知道函数F(x)=Σf(d) d|x,那么我们可以推出f(x)=Σmiu(d)*F(x/d) d|x,另一基本形式为假设知道函数F(x)=Σf(d) x|d,那么我们 ...

  10. kvm源代码分析

    vmx是x86硬件虚拟化层,从代码看,qemu用户态是一层,kernel中KVM通用代码是一层,类似kvm_x86_ops是一层,针对各个不同的硬件架构,而vcpu_vmx则是具体架构的虚拟化方案一层 ...