题目链接: https://codeforces.ml/contest/1492/problem/D
大体题意就是给你a个0,b个1,一个数字k 让你构造一个二进制数x,y x和y包含a个0,b个1且x-y包含恰好k个1.
思路:一开始弱弱想错了,构造的方法是
10000 100000
10000 000001
这样最多可以构造a-1个1.
101100 1111111110
101100 0111111111
但是这样可以使得答案最多,a+b-2个 其实与上面的一样,就是把最后一段的0变成了1(其实什么都无所谓)接下里就是实现1 1 0和1 0 1了,注意特殊情况判断就行了。PS:弱弱写的代码很蠢
D. Genius’s Gambit
time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
You are given three integers a, b, k.
Find two binary integers x and y (x≥y) such that
both x and y consist of a zeroes and b ones;
x−y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0≤a; 1≤b; 0≤k≤a+b≤2⋅105) — the number of zeroes, ones, and the number of ones in the result.
Output
If it’s possible to find two suitable integers, print “Yes” followed by x and y in base-2.
Otherwise print “No”.
If there are multiple possible answers, print any of them.
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
typedef long long ll;
using namespace std;
#define rep(i,j,n) for(ll i=j;i<=n;i++)
#define per(i,j,n) for(ll i=j;i>=n;i--)
#define pr(x) printf("%lld\n",x)
#define pb(x) push_back(x)
typedef unsigned long long ull;
typedef unsigned int us;
const ll INF=1e18+7;const double eps=1e-8;
const ll mod=1e9+7;
const ll maxx=2e5+700;
inline bool read(ll &num){char in;bool IsN=false;in=getchar();if(in==EOF) return false;while(in!='-'&&(in<'0'||in>'9')) in=getchar();if(in=='-'){ IsN=true;num=0;}else num=in-'0';while(in=getchar(),in>='0'&&in<='9'){num*=10,num+=in-'0';}if(IsN) num=-num;return true;}
ll n,m,k,p;
const int zhi=1e7;
ll a,b;
ll num1[maxx],num2[maxx];
void work()
{
ll a1=a-1,b1=b-2;
num1[1]=0;
num1[a+b]=1;
rep(i,2,k)
{
if(b1)
{
b1--;
num1[i]=1;
num2[i]=1;
}
else
{
a1--;
num1[i]=0;
num2[i]=0;
}
}
num1[k+1]=1;
rep(i,k+2,a+b-1)
{
if(b1)
{
b1--;
num1[i]=1;
num2[i]=1;
}
else
{
a1--;
num1[i]=0;
num2[i]=0;
}
}
num2[1]=1;
num2[a+b]=1;
per(i,a+b,1) printf("%lld",num1[i]);
printf("\n");
per(i,a+b,1) printf("%lld",num2[i]);
printf("\n");
}
int main()
{
ll t;
cin>>a>>b>>k;
if(a==0||k==0)
{
if(a==0&&k!=0) printf("No\n");
else
{
printf("Yes\n");
rep(i,1,b) printf("1");
rep(i,1,a) printf("0");
printf("\n");
rep(i,1,b) printf("1");
rep(i,1,a) printf("0");
printf("\n");
}
}
else if(k>(a+b-2))
{
printf("No\n");
}
else
{
if(b==1)
{
if(k==0)
{
printf("Yes\n");
work();
}
else
printf("No\n");
}
else
{
printf("Yes\n");
work();
}
}
return 0;
}