zoukankan      html  css  js  c++  java
  • Codeforces Round #713 (Div. 3) Person Editorial

    补题链接:Here

    1512A - Spy Detected!

    题意:找到唯一不同数的下标

    复制数组然后比较 (a_1)

    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        int _;
        for (cin >> _; _--;) {
            int n;
            cin >> n;
            vector<int> v(n);
            for (int &e : v) {
                cin >> e;
            }
            vector<int> a = v;
            sort(a.begin(), a.end());
            for (int i = 0; i < n; i++) {
                if (v[i] != a[1]) {
                    cout << i + 1 << "
    ";
                }
            }
        }
        return 0;
    }
    

    1512B - Almost Rectangle

    题意:给定 (n imes n).* 坐标图,* 仅两个找到对称位置使 4 个 * 构成矩阵

    分别考虑 同行、同列、不同行同列

    struct node {
        int x, y;
    };
    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        int _;
        for (cin >> _; _--;) {
            int n;
            cin >> n;
            vector<string> a(n);
            for (int i = 0; i < n; ++i) cin >> a[i];
            vector<node> star;
            bool f = false;
            for (int i = 0; i < n && !f; ++i)
                for (int j = 0; j < n && !f; ++j) {
                    if (a[i][j] == '*') {
                        star.push_back({i, j});
                    }
                    if (star.size() == 2) f = true;
                }
            // 同行
            if (star[0].x == star[1].x) {
                if (star[0].x + 1 < n) {
                    a[star[0].x + 1][star[0].y] = '*';
                    a[star[1].x + 1][star[1].y] = '*';
                } else {
                    a[star[0].x - 1][star[0].y] = '*';
                    a[star[1].x - 1][star[1].y] = '*';
                }
            } else if (star[0].y == star[1].y) { // 同列
                if (star[0].y + 1 < n) {
                    a[star[0].x][star[0].y + 1] = '*';
                    a[star[1].x][star[1].y + 1] = '*';
                } else {
                    a[star[0].x][star[0].y - 1] = '*';
                    a[star[1].x][star[1].y - 1] = '*';
                }
            } else {
                a[star[0].x][star[1].y] = '*';
                a[star[1].x][star[0].y] = '*';
            }
    
            for (int i = 0; i < n; ++i) {
                cout << a[i] << "
    ";
            }
        }
        return 0;
    }
    

    1512C - A-B Palindrome

    题意:是否能把字符串中的 ? 替换为 10 使得字符串为回文串。

    注意点:长度为奇数时,如果中点是 ? 则提前处理掉

    AC 代码:

    string solve() {
        int a, b;
        string s;
        cin >> a >> b >> s;
        int n = a + b;
        for (int i = 0; i < s.size(); i++)
            if (s[i] == '1' && s[n - 1 - i] == '0')
                return "-1";
        for (int i = 0; i < s.size(); i++)
            if (s[i] == '?')
                s[i] = s[n - 1 - i];
        if (n % 2 && s[n / 2] == '?')
            if (a % 2)
                s[n / 2] = '0';
            else
                s[n / 2] = '1';
        for (char c : s)
            if (c == '0')
                a--;
            else if (c == '1')
                b--;
        if (a % 2 || b % 2 || a < 0 || b < 0)
            return "-1";
        for (int i = 0; i < s.size(); i++)
            if (s[i] == '?')
                if (a)
                    s[i] = s[n - 1 - i] = '0', a -= 2;
                else
                    s[i] = s[n - 1 - i] = '1', b -= 2;
        return s;
    }
    int main() {
        ios_base::sync_with_stdio(false), cin.tie(0);
        int _;
        for (cin >> _; _--;) {
            cout << solve() << "
    ";
        }
        return 0;
    }
    

    1512D - Corrupted Array

    (b) 中所有元素的总和是多少? 这是 (a + x) 中所有元素之和的两倍。
    (B) 表示 (b) 的所有元素的总和。 让我们迭代添加哪些数组元素作为元素 (a) 的总和(以 (a) 表示)。 然后,(x = B-2⋅A)。 剩下的要检查的是元素 (x) 是否存在于数组 (b)

    上面的思路可以使用哈希表或二进制搜索树来完成。

    using ll = long long;
    void solve() {
        int n;
        cin >> n;
        vector<ll> b(n + 2);
        for (int i = 0; i < n + 2; i++)
            cin >> b[i];
        sort(b.begin(), b.end());
        ll sum = 0;
        for (int i = 0; i <= n; i++)
            sum += b[i];
        for (int i = 0; i <= n; i++) {
            if (sum - b[i] == b.back() || sum - b[i] == b[i]) {
                for (int j = 0; j <= n; j++) {
                    if (j != i)
                        cout << b[j] << " ";
                }
                cout << "
    ";
                return;
            }
        }
        cout << "-1
    ";
    }
    

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

  • 相关阅读:
    git指令累计
    vue里函数相互调用,包括watch监听事件调用methods里面的函数
    FPGA实战操作(2) -- PCIe总线(例程设计分析)
    FPGA实战操作(2) -- PCIe总线(协议简述)
    干掉Vivado幺蛾子(2)-- 快速替换debug probes
    FPGA基础学习(9) -- 复位设计
    UltraFast设计法实践(1) -- 初始设计检查
    《UltraFast设计法实践》系列目录
    干掉Vivado幺蛾子(1)-- Xilinx Tcl Store
    FPGA基础学习(8) --内部结构之存储单元
  • 原文地址:https://www.cnblogs.com/RioTian/p/14644273.html
Copyright © 2011-2022 走看看