D-Genius’s Gambit
题意: 两个二进制数 x , y x,y x,y ,都满足 a a a 个 0 0 0 和 b b b 个 1 1 1 。并且 x − y x-y x−y 中含有 k k k 个 1 1 1 。现在找出这样两个数 x , y x,y x,y (二进制表示)。
思路:
1
1
∗
∗
⋯
∗
∗
0
∗
∗
⋯
∗
∗
1
0
∗
∗
⋯
∗
∗
1
∗
∗
⋯
∗
∗
1 \ \ 1**\cdots**\ \ 0\ \ **\cdots**\\ 1 \ \ 0**\cdots**\ \ 1\ \ **\cdots**
1 1∗∗⋯∗∗ 0 ∗∗⋯∗∗1 0∗∗⋯∗∗ 1 ∗∗⋯∗∗
这样构造,只要保证
a
≥
1
,
b
≥
2
,
k
≥
a
+
b
−
2
a \geq 1,b \geq2,k \geq a+b-2
a≥1,b≥2,k≥a+b−2 就有解。
∗
*
∗ 号表示上下行对应位置的元素相等。
代码:
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<algorithm>
#define fi first
#define se second
//#include<stdlib.h>
//#include <time.h>
//srand((unsigned)time(NULL));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
using namespace std;
const int N = 2e6 + 10;
int a, b, k;
void solve() {
if (k == 0) {
cout << "Yes\n";
for (int i = 0; i < b; i++) cout << 1;
for (int i = 0; i < a; i++) cout << 0;
cout << "\n";
for (int i = 0; i < b; i++) cout << 1;
for (int i = 0; i < a; i++) cout << 0;
cout << "\n";
return;
}
if (a < 1 || b < 2 || k > a + b - 2) {
cout << "No\n";
return;
}
string x = "1", y = "1";
b--;
x += "1"; y += "0";
a--; b--;
for (int i = 1; i < k; i++) {
if (a > 0) {
a--;
x += "0"; y += "0";
}
else if (b > 0) {
b--;
x += "1"; y += "1";
}
}
x += "0"; y += "1";
while (a--) {
x += "0"; y += "0";
}
while (b--) {
x += "1"; y += "1";
}
cout << "Yes\n";
cout << x << "\n";
cout << y << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> a >> b >> k;
solve();
return 0;
}