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时,说明序列中含有
01
或10
,我们可以构造长度为 b + 1 b+1 b+1的10…1010
序列,这样就满足了有 b b b对相邻的数和为 1 1 1 - 然后我们可以在第一个
0
前插入 a a a个0
,第一个1
前插入 c c c个1
,这样就满足了有 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;
}