题目链接
题目大意
让你构造两个二进制数\(x,y(y \leq x)\)
\(x,y\)有\(a\)个\(0\),\(b\)个\(1\)
要使得\(x-y\)有\(k\)个\(1\)
\(0\leq a; 1\leq b;0\leq k\leq a+b\leq 2e5\)
题目思路
其实很简单就是
11xxxx0xxx
10xxxx1xxx
x代表相同
则\(k\leq a+b-2\)则可以构造
还要一些边界情况特殊考虑即可
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int a,b,k;
int ans1[maxn],ans2[maxn];
void pr(int x,int len){
while(len--){
printf("%d",x);
}
}
int main(){
scanf("%d%d%d",&a,&b,&k);
if(a==0){
if(k==0){
printf("Yes\n");
pr(1,b);
printf("\n");
pr(1,b);
printf("\n");
}else{
printf("No\n");
}
}else if(b==1){
if(k==0){
printf("Yes\n");
pr(1,1),pr(0,a);
printf("\n");
pr(1,1),pr(0,a);
printf("\n");
}else{
printf("No\n");
}
}else if(k==0){
printf("Yes\n");
pr(1,b),pr(0,a);
printf("\n");
pr(1,b),pr(0,a);
printf("\n");
}else if(k<=a+b-2){
printf("Yes\n");
for(int i=1;i<=a+b;i++){
if(i<=b){
ans1[i]=ans2[i]=1;
}else{
ans1[i]=ans2[i]=0;
}
}
swap(ans1[k+2],ans1[a+b]);
swap(ans2[2],ans2[a+b]);
swap(ans2[k+2],ans2[a+b]);
for(int i=1;i<=a+b;i++){
printf("%d",ans1[i]);
}
printf("\n");
for(int i=1;i<=a+b;i++){
printf("%d",ans2[i]);
}
printf("\n");
}else{
printf("No\n");
}
return 0;
}