【比赛链接】
【题解链接】
**【Div.2 A】**Golden Plate
【思路要点】
- 直接循环计算答案即可。
- 时间复杂度 O ( K ) O(K) O(K) 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) {x = max(x, y); } template <typename T> void chkmin(T &x, T y) {x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int main() { int n, m, k; read(n), read(m), read(k); int ans = 0; for (int i = 1; i <= k; i++) { int x = n - 4 * (i - 1); int y = m - 4 * (i - 1); ans += x * 2 + y * 2 - 4; } writeln(ans); return 0; }
**【Div.2 B】**Curiosity Has No Limits
【思路要点】
- 首先,每一位的方案是相互独立的,我们可以分开考虑。
- 当确定 x , x & y , x ∣ y x,x\&y,x|y x,x&y,x∣y 时,合法的 y y y 至多只有 1 1 1 个。
- 因此枚举开头位置,构造出序列,再检验合法性即可。
- 时间复杂度 O ( N ) O(N) O(N) 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) {x = max(x, y); } template <typename T> void chkmin(T &x, T y) {x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int n, a[MAXN], b[MAXN], x[MAXN]; int func(int a, int b, int x) { if (a == b) return a; else if (a == 0) return 0; else return 1 - x; } bool tryans(int f) { x[1] = f; for (int i = 1; i <= n - 1; i++) x[i + 1] = func(a[i] / 2, b[i] / 2, x[i] / 2) * 2 + func(a[i] % 2, b[i] % 2, x[i] % 2); for (int i = 1; i <= n - 1; i++) { if ((x[i] | x[i + 1]) != a[i]) return false; if ((x[i] & x[i + 1]) != b[i]) return false; } return true; } void answer() { printf("YES\n"); for (int i = 1; i <= n; i++) printf("%d ", x[i]); exit(0); } int main() { read(n); for (int i = 1; i <= n - 1; i++) read(a[i]); for (int i = 1; i <= n - 1; i++) read(b[i]); if (tryans(0)) answer(); if (tryans(1)) answer(); if (tryans(2)) answer(); if (tryans(3)) answer(); printf("NO\n"); return 0; }
**【Div.2 C/Div.1 A】**Cram Time
【思路要点】
- 记 x x x 表示最大的使得 x ( x + 1 ) 2 ≤ a + b \frac{x(x+1)}{2}≤a+b 2x(x+1)≤a+b 的整数,答案显然有上界为 x x x 。
- 若我们保证第一天用完刚好 a a a 小时或完成所有 x x x 个任务,那么答案将一定会取到上界。只需要从大到小考虑每个任务,优先将其安排在第一天即可。
- 时间复杂度 O ( a + b ) O(\sqrt{a+b}) O(a+b) 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) {x = max(x, y); } template <typename T> void chkmin(T &x, T y) {x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } vector <int> a, b; int main() { int n, m; read(n), read(m); int sum = n + m, tot = 0; while (sum >= tot + 1) { tot++; sum -= tot; } for (int i = tot; i >= 1; i--) if (n >= i) { n -= i; a.push_back(i); } else b.push_back(i); writeln(a.size()); for (auto x : a) printf("%d ", x); printf("\n"); writeln(b.size()); for (auto x : b) printf("%d ", x); printf("\n"); return 0; }
**【Div.2 D/Div.1 B】**Minimum path
【思路要点】
- 分层 D P DP DP ,令点 ( i , j ) (i,j) (i,j) 为第 i + j − 1 i+j-1 i+j−1 层的点。
- 首先确定答案的第 i i i 位 a n s i ans_i ansi ,再计算得出能够取到最优答案的第