zoukankan      html  css  js  c++  java
  • Codeforces Round #712 (Div. 2) 个人题解

    这一场打的又很差(掉分预定),D题想不出来。

    A. Déjà Vu

    这题首先判断字符串是否全由 a 组成,如果是的话输出 NO

    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        int _;
        for (cin >> _; _--;) {
            string s;
            cin >> s;
            int N = s.length();
            // find_first_not_of
             auto i = s.find_first_not_of('a');
            if (i == string::npos) {
                cout << "NO
    ";
                continue;
            }
            int j = (i < N / 2 ? N - i : N - i - 1);
            cout << "YES
    ";
            cout << s.substr(0, j) << 'a' << s.substr(j) << "
    ";
        }
        return 0;
    }
    

    B. Flip the Bits

    题意:给你一个 01 初始序列和目标序列,每次可以选择前 (2 imes x) 个位置异或1(前提是选择区域的0和1个数相等),问你有没有办法变成目标序列。

    思路:待补

    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        int _;
        for (cin >> _; _--;) {
            int n;
            string a, b;
            cin >> n >> a >> b;
            int sa = 0, sb = 0;
            bool f = true;
            for (int i = 0; i < n; ++i) {
                sa += 2 * (a[i] - '0') - 1;
                sb += 2 * (b[i] - '0') - 1;
                // cout << sa << " " << sb << "
    ";
                f = f && abs(sa) == abs(sb);
            }
            // cout << sa << " " << sb << "
    ";
            f = f && sa == sb;
            cout << (f ? "YES
    " : "NO
    ");
        }
        return 0;
    }
    

    C. Balance the Bits

    题意:给你一个01序列,问你能不能构造两个合法的括号序列a,b,使得当 (s[i] = 1) 时,(a[i] = b[i]) ,当 (s[i] = 0) 时,(a[i] != b[i])

    思路:首先,两个字符串序列必须以( 开头,) 结尾,其实,由于 ()的个数和 (n) 为偶数所以 (s) 序列中 1 的个数也必为偶数。

    接下来就是模拟条件了

    AC 代码

    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        int _;
        for (cin >> _; _--;) {
            int n, t = 0;
            string s;
            cin >> n >> s;
            int cnt = count(s.begin(), s.end(), '1');
            if (s[0] != '1' || s[n - 1] != '1' || cnt & 1) {
                cout << "NO
    ";
                continue;
            }
            cnt /= 2;
            string a(n, '*'), b(n, '*');
            for (int i = 0; i < n; ++i) {
                if (s[i] == '0') {
                    if (t == 0) a[i] = ')', b[i] = '(';
                    else
                        a[i] = '(', b[i] = ')';
                    t ^= 1;
                } else {
                    if (cnt) {
                        a[i] = b[i] = '(';
                        cnt--;
                    } else
                        a[i] = b[i] = ')';
                }
            }
            cout << "YES
    ";
            cout << a << "
    "
                 << b << '
    ';
        }
        return 0;
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    python3 TypeError: a bytes-like object is required, not 'str'
    Centos 安装Python Scrapy PhantomJS
    Linux alias
    Vim vimrc配置
    Windows下 Python Selenium PhantomJS 抓取网页并截图
    Linux sort
    Linux RSync 搭建
    SSH隧道 访问内网机
    笔记《鸟哥的Linux私房菜》7 Linux档案与目录管理
    Tornado 错误 "Global name 'memoryview' is not defined"
  • 原文地址:https://www.cnblogs.com/RioTian/p/14616918.html
Copyright © 2011-2022 走看看