CF1694A Creep 的题解

CF1694A Creep 的题解

洛谷传送门
CF传送门

题目大意

请你构造出一个有 a a a 0 0 0 b b b 1 1 1 的字符串,使它的 0 0 0 1 1 1 的个数相差最多的前缀, 0 0 0 1 1 1 的个数相差最少。若有多种答案,输出任意一种。多组数据。

思路

先输出 min ⁡ ( a , b ) \min(a,b) min(a,b) 个连续的 0 0 0 1 1 1,让 0 0 0 1 1 1 的前缀差最小,最后再依次输出剩余的其他数字。注意最后需要换行。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
	inline int read() {
		register int x = 0, f = 1;
		register char c = getchar();
		while (c < '0' || c > '9') {
			if(c == '-') f = -1;
			c = getchar();
		}
		while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
		return x * f;
	}
	inline void write(int x) {
		if(x < 0) putchar('-'), x = -x;
		if(x > 9) write(x / 10);
		putchar(x % 10 + '0');
		return;
	}
}
using namespace fastIO;
signed main() {
	int T;
	cin >> T;
    for (int i = 1; i <= T; i ++) {
        int a, b;
        cin >> a >> b;
        int minn = min(a, b);
        for (int j = 1; j <= minn; j ++) {
            cout << "01";
        }
        a = a - minn;
        b = b - minn;
        for (int j = 1; j <= a; j ++) {
            cout << 0;
        }
        for (int j = 1; j <= b; j ++) {
            cout << 1;
        }
        cout << endl; // 注意换行
    }
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值