zoukankan      html  css  js  c++  java
  • Codeforces Round #715 (Div. 2) (A~D 补题记录)

    补题链接:Here

    经典手速场

    1509A. Average Height

    题意:要找出最大不平衡对序列

    先输出奇数,然后输出偶数

    void solve() {
        int n;
        cin >> n;
        vector<int> odd, even;
        for (int i = 0, x; i < n; ++i) {
            cin >> x;
            if (x & 1) odd.push_back(x);
            else
                even.push_back(x);
        }
        for (int x : odd) cout << x << " ";
        for (int x : even) cout << x << " ";
        cout << "
    ";
    }
    

    1509B. TMT Document

    题意:给定一个 T-M字符串,求问是否能全拆分为 TMT 子序列

    思路:

    要能组成 TMT 就要是 T、M顺序一定并 cntT = 2 * cntM(n \% 3== 0)

    void solve() {
        int n;
        string s;
        cin >> n >> s;
        int ct = 0, cm = 0;
        bool f = true;
        for (int i = 0; f && i < n; ++i) {
            s[i] == 'T' ? ct++ : cm++;
            if (cm > ct || (ct > 2 * cm + n / 3 - cm)) f = false;
        }
        cout << (f && cm * 2 == ct && n % 3 == 0 ? "YES
    " : "NO
    ");
    }
    

    1509C. The Sports Festival

    题意:

    学生会要参加接力赛,每位成员跑步速度为 (a_i) ,给定定义:

    [d_i = max(a_1,a_2,dots,a_i) - min(a_1,a_2,dots,a_i) ]

    求出最小的 (sum_{i = 1}^n d_i)

    思路:

    待补。

    using ll = long long;
    ll dp[2005][2005];
    int n;
    int A[2005];
    void solve() {
        cin >> n;
        for (int i = 1; i <= n; ++i) cin >> A[i];
        sort(A + 1, A + n + 1);
        for (int i = 1; i <= n; ++i)
            for (int j = i + 1; j <= n; ++j) dp[i][j] = 1e18;
        for (int i = 1; i <= n; ++i) dp[i][i] = 0;
        for (int len = 1; len < n; ++len) {
            for (int i = 1; i + len - 1 <= n; ++i) {
                int j = i + len - 1;
                if (j < n) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + A[j + 1] - A[i]);
                if (i > 1) dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] + A[j] - A[i - 1]);
            }
        }
        cout << dp[1][n] << '
    ';
    }
    

    另外一种写法

    using ll = long long;
    void solve() {
        int n;
        cin >> n;
        vector<ll> s(n);
        for (ll &x : s) cin >> x;
        sort(s.begin(), s.end());
        vector<ll> dp0(n), dp1(n);
        for (int k = 1; k < n; ++k) {
            for (int i = k; i < n; ++i)
                dp1[i] = min(dp0[i - 1], dp0[i]) + s[i] - s[i - k];
            swap(dp0, dp1);
        }
        cout << dp0[n - 1] << '
    ';
    }
    

    1508A/1509D. Binary Literature

    题意:

    在一场二进制小说写作比赛中,需要由三个长度为 (2 · n) 的字符串组成的 (3 · n) 长度的字符串(其中至少包括 (3) 个字符串的两个作为子序列)

    先贴一下AC代码

    void solve() {
        int n;
        string a, b, c;
        cin >> n >> a >> b >> c;
        int x = 0, y = 0, z = 0;
        for (int i = 0; i < 2 * n; ++i) {
            if (a[i] == '1') ++x;
            if (b[i] == '1') ++y;
            if (c[i] == '1') ++z;
        }
        if (x > y) swap(a, b), swap(x, y);
        if (y > z) swap(b, c), swap(y, z);
        if (x > y) swap(a, b), swap(x, y);
        char cc = '0';
        if (y > n) {
            cc = '1';
            swap(a, c), swap(x, z);
        }
        x = y      = 0;
        string ans = "";
        while (true) {
            while (x < 2 * n && a[x] != cc) ans += a[x], ++x;
            while (y < 2 * n && b[y] != cc) ans += b[y], ++y;
            if (x == 2 * n && y == 2 * n) break;
            ans += cc;
            if (x < 2 * n) x++;
            if (y < 2 * n) y++;
        }
        while (ans.size() < 3 * n) ans += '0';
        cout << ans << '
    ';
    }
    

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

  • 相关阅读:
    Spring 注解之 @Conditional
    Spring 注解之 @Scope @Lazy
    Spring 注解之 @ComponentScan
    泛型
    Spring AOP概述
    SpringIOC基于注解创建对象和注入属性
    静态代理和动态代理
    shinobi(3)
    miniupnpd初略理解和实际使用
    shinobi(2)
  • 原文地址:https://www.cnblogs.com/RioTian/p/14669549.html
Copyright © 2011-2022 走看看