D-Genius‘s Gambit(构造)

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 xy 中含有 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 a1,b2,ka+b2 就有解。 ∗ * 号表示上下行对应位置的元素相等。

代码:

#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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值