Codeforces Round #633 (Div. 2)

比赛链接:https://codeforces.com/contest/1339

A. Filling Diamonds

竖着放会引起连锁,使得其他所有位置不得不横放适应这个竖着放的位置,所以直接输出竖着放有多少种情况即可。

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin >> n;
    cout << n << "
";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

B. Sorted Adjacent Differences

从中间向两边输出即可。

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin >> n;
    int a[n]; for (int & i : a) cin >> i;
    sort(a, a + n);
    int l, r;
    if (n % 2) {
        cout << a[n / 2] << ' ';
        l = n / 2 - 1;
        r = n / 2 + 1;
    } else {
        l = n / 2 - 1;
        r = n / 2;
    }
    while (l >= 0) {
        cout << a[l] << ' ' << a[r] << ' ';
        --l, ++r;
    }
    cout << "
";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

C. Powered Addition

如果有 $a_i>a_{i+1}$,那么后者一定可以经过变换与前者相等,因为二者之差可以表示为一个二进制数,我们每次只取为 $1$ 的幂次即可,所求答案即为所有差中最高的幂次。

#include <bits/stdc++.h>
using ll = long long;
using namespace std;

void solve() {
    int n; cin >> n;
    ll a[n]; for (ll & i : a) cin >> i;
    if (n == 1 || (a[0] <= a[1] && is_sorted(a, a + n))) {
        cout << "0
";
        return;
    } 
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] > a[i + 1]) {
            int sub = a[i] - a[i + 1];
            int cnt = 0;
            while (sub) {
                ++cnt;
                sub >>= 1;
            }
            ans = max(ans, cnt);
            a[i + 1] = a[i];
        }
    }
    cout << ans << "
";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

D. Edge Weight Assignment

图这块还是不太熟悉,搞了近一个半小时,待填。

原文地址:https://www.cnblogs.com/Kanoon/p/12688919.html