Educational Codeforces Round 102 Personal Editorial(A~C,max Rating 1500)

1473A. Replacing Elements Rating 800

对数组排序,一旦数组中最大的数即a[n-1]是一个小于或等于d的数,直接输出YES即可,否则运用数组中最小的两个数加和替换最大的数。

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    for (cin >> _; _--;) {
        int n, d;
        cin >> n >> d;
        vector<int> a(n);
        for (auto &i : a) cin >> i;
        sort(a.begin(), a.end());
        cout << (a[n - 1] <= d || a[0] + a[1] <= d ? "YES
" : "NO
");
    }
    return 0;
}

1473B. String LCM Rating 1000

给两个只由a和b组成的字符串,让你求出即符合a的变化规律又符合b的变化规律的,长度即能被a的长度整除也能被b的长度整除的最短字符串。

那么模拟一下过程即可

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    for (cin >> _; _--;) {
        string a, b;
        cin >> a >> b;
        string p = a, q = b;
        while (true) {
            if (p.length() == q.length()) {
                if (p == q)
                    cout << p << endl;
                else
                    cout << -1 << endl;
                break;
            }
            if (p.length() < q.length())
                p += a;
            else
                q += b;
        }
    }
    return 0;
}

1473C. No More Inversions Rating 1500

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    for (cin >> _; _--;) {
        int n, k;
        cin >> n >> k;
        for (int i = 1; i < 2 * k - n; i++) cout << i << ' ';
        // 2 * k - n即 k - (n - k)的变形
        for (int i = k; i >= 2 * k - n; i--) cout << i << ' ';
        cout << endl;
    }
    return 0;
}

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

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