Codeforces Round #494 (Div. 3) ----B
程序员文章站
2022-06-02 12:05:43
...
输出一串01串,其中有x个位置满足 Si != Si+1
我们先输出x/2个01或者10串,01还是10串,取决于0多还是1多,之后输出剩下的串,判读x的奇偶性,奇数的话,就先输出剩下的多的那个数字,然后输出少的,偶数相反
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,x,p,q;
cin >> a >> b >> x;
if (a > b) { p = 0 ; q = 1;}
else { p = 1 ; q = 0;}
for (int i=0; i<x/2; i++) {
cout << p << q;
a--; b--;
}
if (x & 1) {
for (int i=0; i<max(a, b); i++) {
cout << p;
}
for (int i=0; i<min(a, b); i++) {
cout << q;
}
}else{
for (int i=0; i<min(a, b); i++) {
cout << q;
}
for (int i=0; i<max(a, b); i++) {
cout << p;
}
}
cout << endl;
return 0;
}
上一篇: 南京周边最适合亲子自驾游目的地推荐
下一篇: 1396 还是01串
推荐阅读
-
Codeforces Round #595 (Div. 3)D1D2 贪心 STL
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #656 (Div. 3)D. a-Good String(递归+dfs)
-
Codeforces Round #487 (Div. 2)
-
CodeForces 1324 - Codeforces Round #627 (Div. 3)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #610 (Div. 2)