Educational Codeforces Round 106 (Rated for Div. 2) 简单题解(A~C)

1499A. Domino on Windowsill

题意:给定一个 (2 imes n) 的空间,(k1、k2 行要设置为白色(2 imes 1)) 然后其他的设置为黑色

思路:为了满足条件需要判断一下白色和黑色的方块是否足够。

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    for (cin >> _; _--;) {
        int n, k1, k2, w, b;
        cin >> n >> k1 >> k2 >> w >> b;
        if (2 * w <= k1 + k2 and 2 * b <= 2 * n - k1 - k2) cout << "YES
";
        else
            cout << "NO
";
    }
    return 0;
}

1499B. Binary Removals

找下前缀的 0和后缀的 1的个数进行比较

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    for (cin >> _; _--;) {
        string s;
        cin >> s;
        int L = 0, R = s.size() - 1;
        while (L < s.size() and (s[L] == '0' or (L == 0 or s[L - 1] == '0')))
            L++;
        while (R >= 0 and
               (s[R] == '1' or (R == (int)s.size() - 1 or s[R + 1] == '1')))
            R--;
        if (L >= R) cout << "YES
";
        else
            cout << "NO
";
    }
    return 0;
}

学习高 Rank 的大佬写法

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    for (cin >> _; _--;) {
        string s;
        cin >> s;
        int i = s.find("11");
        int j = s.rfind("00");
        cout << (i != -1 && j != -1 && i < j ? "NO" : "YES") << endl;
    }
    return 0;
}

1499C. Minimum Grid Path

using ll = long long;
int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    for (cin >> _; _--;) {
        int n;
        cin >> n;
        vector<int> c(n);
        ll ans = LLONG_MAX;
        ll mi[2] = {(ll)1E13, (ll)1E13}, sm[2] = {0, 0}, cnt[2] = {0, 0};
        for (int i = 0; i < n; ++i) {
            ll c;
            cin >> c;
            mi[i & 1] = min(mi[i & 1], c);
            cnt[i & 1] += 1;
            sm[i & 1] += c;
            ans = min(ans, mi[0] * (n - cnt[0]) + sm[0] + mi[1] * (n - cnt[1]) +
                               sm[1]);
        }
        cout << ans << "
";
    }
    return 0;
}

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

原文地址:https://www.cnblogs.com/RioTian/p/14561444.html