You are given three integers , , .
Find two binary integers and () such that
The only line contains three integers , , and (; ; ) — the number of zeroes, ones, and the number of ones in the result.
If it‘s possible to find two suitable integers, print "Yes" followed by and in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
4 2 3
Yes 101000 100001
3 2 1
Yes 10100 10010
3 2 5
No
In the first example, , , . Hence has ones in base-2.
In the second example, , , . This is precisely one 1.
In the third example, one may show, that it‘s impossible to find an answer.
题意:balabala
题解:思维题,通过构造能够得到最多a+b-2个1,
我们通过先想最简单的做法不难得到当b=2时显而易见这种方式能够得到最多的1:
110000000
100000001
并且我们可以移动第二位的数对(1,0)来得到最多a+b-2个1,是以这种方式移动的:
100010000
100000001(相减得到4个1)
我们再考虑b>=3的情况来看:
例如:
111100000
101100001
显而易见,我们可以移动第二位的数对(1,0)来得到最多不超过a+b-2个1,如果还不明白,这是因为上面相减依然可以写成:
110000000
100000001
很熟悉吧,就变成了b=2时的简单情况,于是我们就会处理了!
(代码有点乱)
\(Coding:\)
/*************************************************************************
> File Name: D.cpp
# Author: Badwoman
# mail: 1194446133@qq.com
> Created Time: 2021年03月03日 星期三 19时38分22秒
************************************************************************/
#include<set>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define bep(i,a,b) for(int i=a;i>=b;--i)
#define lowbit(x) (x&(-x))
using namespace std;
int a,b,k;
void solve(){
scanf("%d%d%d",&a,&b,&k);
int mx = a + b - 2 ;
int n = a + b ;
if(!a){
if(k)printf("No");
else {
puts("Yes");
rep(i,1,2){
rep(j,1,n)printf("1");puts("");
}
}return ;
}
if(k>mx)puts("No");
else {
if(b == 1){
if(k)puts("No");
else {
puts("Yes");
rep(j,1,2){
printf("1");
rep(i,1,a)printf("0");
puts("");
}
}
}
else if(b == 2){
puts("Yes");
printf("1");
int now = 2;
rep(i,2,n-k-1)printf("0");
printf("1");
rep(i,n-k,n-1)printf("0");
puts("");
printf("1");
rep(i,2,n-1)printf("0");
puts("1");
}
else {
puts("Yes");
rep(i,1,n){
if(i<=b-1||i==n-k||(n-k<=b-1&&i==b))printf("1");
else printf("0");
}
puts("");
int cnt = 0;
rep(i,1,n-1){
if(i==n-k)printf("0");
else if(cnt<b-1)printf("1"),cnt++;
else printf("0");
}
puts("1");
}
}
}
signed main(){
solve();
return 0;
}
codeforces 704(div.2)D. Genius's Gambit
原文:https://www.cnblogs.com/violentbear/p/14476730.html