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;
}