2025暑假提高级冲刺集训班-5 题解
_TwilightSnow_ · · 题解
T1 [COCI 2022/2023 #2] Prijateljice
直接模拟即可,每次判断是否能够说出答案,不能的话对方就赢了。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int, int>
#define VI vector<int>
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define up(i, s, t) for (int i = s; i < t; i++)
#define dw(i, s, t) for (int i = s - 1; i >= t; i--)
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<string> a(n), b(m);
up(i, 0, n) cin >> a[i];
up(i, 0, m) cin >> b[i];
sort(all(a)), sort(all(b));
int pl = 0, pz = 0, ansl = 1, ansz = 1;
while (ansl && ansz) {
ansl = ansz = 0;
up(i, pz, m)
if (b[i] > a[pl] && b[i][0] - a[pl][0] <= 1) {
pz = i, ansz = 1;
break;
}
up(i, pl, n)
if (a[i] > b[pz] && a[i][0] - b[pz][0] <= 1) {
pl = i, ansl = 1;
break;
}
}
if (ansz) cout << "Zoe";
else cout << "Leona";
return 0;
}
T2 [USACO18DEC] Teamwork G
简单 DP。
设
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define up(i, s, t) for (int i = s; i <= t; i++)
#define dw(i, s, t) for (int i = s; i >= t; i--)
const int N = 1e4 + 2;
int n, k, res, a[N], f[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> k;
up(i, 1, n) cin >> a[i];
up(i, 1, n) {
int mx = a[i];
dw(j, i - 1, max(0ll, i - k)) {
f[i] = max(f[i], f[j] + mx * (i - j));
mx = max(mx, a[j]);
}
}
cout << f[n] << '\n';
return 0;
}
T3 [ARC137B] Count 1's
因为
计算的话可以使用前缀和,以
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define up(i, s, t) for (int i = s; i <= t; i++)
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int mx = 0, mn = 0, mxr = 0, mnr = 0, n, a, s = 0;
cin >> n;
up(i, 1, n) {
cin >> a, s += a ? -1 : 1;
mx = max(mx, s), mn = min(mn, s);
mxr = max(mxr, s - mn), mnr = min(mnr, s - mx);
}
cout << mxr - mnr + 1 << '\n';
return 0;
}