Contest link: https://codeforces.com/contest/1339
A. Filling Diamonds
Putting it upright will cause a chain, making all other positions have to adapt to this upright position, so just output how many cases there are.
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; cout << n << "\n"; } int main() { int t; cin >> t; while (t--) solve(); }
B. Sorted Adjacent Differences
Just output from the middle to both sides.
#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 << "\n"; } int main() { int t; cin >> t; while (t--) solve(); }
C. Powered Addition
If there is $ a_i> a_ {i + 1} $, then the latter must be transformed to be equal to the former, because the difference between the two can be expressed as a binary number, we only need to take the power of $ 1 $ each time, The answer sought is the highest power of all differences.
#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\n"; 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; } years = max (years, cnt); a[i + 1] = a[i]; } } cout << ans << "\n"; } int main() { int t; cin >> t; while (t--) solve(); }
D. Edge Weight Assignment
The picture is still not very familiar, it took almost an hour and a half , to be filled.