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

F. Binary String Reconstruction

题目链接-F. Binary String Reconstruction
在这里插入图片描述
在这里插入图片描述
题目大意
构造一个二进制序列,满足有 a a a对相邻的数和为 0 0 0 b b b对相邻的数和为 1 1 1 c c c对相邻的数和为 2 2 2

解题思路

  • 对于和为 2 2 2 c c c对相邻的数,我们只能11这样构造,这是只需 c + 1 c+1 c+1个连续数字1即可,同理和为 0 0 0 a a a对相邻的数,只需 a + 1 a+1 a+1个连续数字0即可,所以我们重点考虑 b b b对相邻的数和为 1 1 1如何构造
  • b b b 0 0 0时,说明该二进制序列中只有 1 1 1 0 0 0,根据情况输出 a + 1 a+1 a+1数量的0 c + 1 c+1 c+1数量的1
  • b b b不为 0 0 0时,说明序列中含有0110,我们可以构造长度为 b + 1 b+1 b+110…1010序列,这样就满足了有 b b b对相邻的数和为 1 1 1
  • 然后我们可以在第一个0前插入 a a a0,第一个1前插入 c c c1,这样就满足了有 a + 1 a+1 a+1个连续数字0 c + 1 c+1 c+1个连续数字0,同时也不影响10对的数目
  • 具体操作见代码

附上代码

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int t;
	cin>>t;
	while(t--){
		int a,b,c;
		cin>>a>>b>>c;
		if(b==0){
			if(a!=0)
				cout<<string(a+1,'0');
			else
				cout<<string(c+1,'1');
		}
		else{
			string ans="";
			for(int i=0;i<b+1;i++)
				i&1?ans+='0':ans+='1';
			ans.insert(1,string(a,'0'));
			ans.insert(0,string(c,'1'));
			cout<<ans;
		}
		cout<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值