首页 > 其他 > 详细

codeforces 704(div.2)D. Genius's Gambit

时间:2021-03-03 21:42:22      阅读:36      评论:0      收藏:0      [点我收藏+]
D. Genius‘s Gambit
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given three integers a, b, k.

Find two binary integers x and y (xy) such that

  1. both x and y consist of a zeroes and b ones;
  2. 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 (0a; 1b; 0ka+b2?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.

Examples
Input
Copy
4 2 3
Output
Copy
Yes
101000
100001
Input
Copy
3 2 1
Output
Copy
Yes
10100
10010
Input
Copy
3 2 5
Output
Copy
No
Note

In the first example, x=1010002=25+23=4010, y=1000012=25+20=3310, 4010?3310=710=22+21+20=1112. Hence x?y has 3 ones in base-2.

In the second example, x=101002=24+22=2010, y=100102=24+21=18, x?y=20?18=210=102. 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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!