【比赛链接】
【题解链接】
【Div.2 A】Splits
【思路要点】
- 由于我们希望得到尽可能不同的权值,我们可以考虑在拆分的开头放置若干个2,然后放1填补剩余的数字。
- 不难发现答案等于\(\lfloor\frac{N}{2}\rfloor+1\)。
- 时间复杂度\(O(1)\)。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 100005; 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; read(n); writeln(n / 2 + 1); return 0; }
【Div.2 B】Messages
【思路要点】
- 考虑到阅读信息的收益是关于时间的一次函数,最值一定可以在端点处取到。
- 在收到信息立刻阅读与留到最后阅读两个方案中取较大者即可。
- 时间复杂度\(O(N)\)。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 100005; 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, A, B, C, T, ans = 0; read(n), read(A), read(B), read(C), read(T); for (int i = 1; i <= n; i++) { int x; read(x); ans += A; if (C >= B) ans += (T - x) * (C - B); } writeln(ans); return 0; }
【Div.2 C/Div.1 A】Al