CF 怎么了,求助
  • 板块题目总版
  • 楼主kimi0705
  • 当前回复9
  • 已保存回复9
  • 发布时间2023/9/2 19:23
  • 上次更新2023/11/2 23:49:07
查看原帖
CF 怎么了,求助
637788
kimi0705楼主2023/9/2 19:23

https://www.luogu.com.cn/discuss/show?postid=678267

#include <bits/stdc++.h>
#define E puts("");
#define S putchar(' ');
#define debug(x) cout << #x << " = " << x << ' ';
using namespace std;
int t, n;
string s1, s2, s3;
int c10, c11,
    c20, c21,
    c30, c31;
int cnt;
bool f1, f2, f3; // fi = 0 表示 0 多, fi = 1 表示 1 多。
string max01() {
    if (c10 >= c20 && c10 >= c30)
        return s1;
    else if (c20 >= c10 && c20 >= c30)
        return s2;
    else
        return s3;
}
string max02() {
    if ((c10 >= c20 && c10 <= c30) || (c10 <= c20 && c10 >= c30)) return s1;
    if ((c20 >= c10 && c20 <= c30) || (c20 <= c10 && c20 >= c30)) return s2;
    if ((c30 >= c10 && c30 <= c20) || (c30 <= c10 && c30 >= c20)) return s3;
}
string max11() {
    if (c11 >= c21 && c11 >= c31)
        return s1;
    else if (c21 >= c11 && c21 >= c31)
        return s2;
    else
        return s3;
}
string max12() {
    if ((c11 >= c21 && c11 <= c31) || (c11 <= c21 && c11 >= c31)) return s1;
    if ((c21 >= c11 && c21 <= c31) || (c21 <= c11 && c21 >= c31)) return s2;
    if ((c31 >= c11 && c31 <= c21) || (c31 <= c11 && c31 >= c21)) return s3;
}
int main() {
    cin >> t;
    while (t--) {
        cin >> n >> s1 >> s2 >> s3;
        n <<= 1;
        c10 = count(s1.begin(), s1.end(), '0');
        c11 = count(s1.begin(), s1.end(), '1');
        c20 = count(s2.begin(), s2.end(), '0');
        c21 = count(s2.begin(), s2.end(), '1');
        c30 = count(s3.begin(), s3.end(), '0');
        c31 = count(s3.begin(), s3.end(), '1');
        f1 = c10 < c11;
        f2 = c20 < c21;
        f3 = c30 < c31;
        cnt = f1 + f2 + f3;
        // debug(f1);
        // debug(f2);
        // debug(f3);
        // debug(cnt);
        if (cnt <= 1) { // 插入 1 的
            int id = 0;
            string t = max01();
            string s = max02();
            // cout << t << ' ' << s << '\n';
            for (int i = 0; i < n; i++) {
                if (t[i] == '0' && id < n && s[id] == '1')
                    cout << 1, id++, i--;
                else if (id < n && t[i] == s[id])
                    cout << t[i], id++;
                else
                    cout << t[i];
            }
            while(id < n) cout << s[id], id++;
        } else { // 插入 0 的
            int id = 0;
            string t = max11();
            string s = max12();
            // cout << t << ' ' << s << '\n';
            for (int i = 0; i < n; i++) {
                if (t[i] == '1' && id < n && s[id] == '0')
                    cout << 0, id++, i--;
                else if (id < n && t[i] == s[id])
                    cout << t[i], id++;
                else
                    cout << t[i];
            }
            while(id < n) cout << s[id], id++;
        }
        E;
    }
}
2023/9/2 19:23
加载中...