1496A. Split it!
类回文判断,只要 k = 0 或者 是回文即可
特判情况 n < 2 * k + 1 为 NO
int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _ = 1;for (cin >> _; _--;) {string s;int n; ll k;cin >> n >> k;cin >> s;bool f = true;for (int i = 0; i < k && f; ++i) f = s[i] == s[n - i - 1]);cout << (f && n >= 2 * k + 1 ? "YES\n" : "NO\n");}return 0;}
1496B. Max and Mex
模拟,当 mex(a) < max(b) 时 必有 则集合不一样的数可增加一,否则每进行一次操作 + 1
int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _ = 1;for (cin >> _; _--;) {int n;ll k;cin >> n >> k;vector<ll> a(n);set<ll> s;for (int i = 0; i < n; ++i) {cin >> a[i];s.insert(a[i]);}sort(a.begin(), a.end());if (k == 0) {cout << s.size() << "\n";continue;}int i = 0;ll b = 0;while (b == a[i]) b++, i++;if (b <= a[n - 1]) {s.insert((b + a[n - 1] + 1) / 2);cout << s.size() << "\n";continue;}cout << s.size() + k << endl;}return 0;}
1496C. Diamond Miner
将坐标绝对值化存入数组排序
%5E2%20%2B(b%20-%20d)%5E2%7D%20%3D%20%5Csqrt%7Ba%5E2%20%2B%20d%5E2%7D#card=math&code=%5Csqrt%7B%28a-c%29%5E2%20%2B%28b%20-%20d%29%5E2%7D%20%3D%20%5Csqrt%7Ba%5E2%20%2B%20d%5E2%7D) 要想有最小化,只能大值匹配大值
int main() {ios_base::sync_with_stdio(false), cin.tie(0);int _ = 1;for (cin >> _; _--;) {int n;cin >> n;vector<int> xx, yy;for (int i = 0; i < 2 * n; ++i) {int x, y;cin >> x >> y;if (x == 0) yy.push_back(abs(y));elsexx.push_back((abs(x)));}sort(xx.begin(), xx.end());sort(yy.begin(), yy.end());double cnt = 0.0;for (int i = 0; i < n; ++i) {cnt += sqrt(1.0 * xx[i] * xx[i] + 1.0 * yy[i] * yy[i]);}cout << setprecision(15) << cnt << "\n";}return 0;}
1496D. Let’s Go Hiking
学习自 洛绫璃 dalao的思路
这是一道博弈题
由于只能存在一条最长链,否则先手站一条, 后手站一条, 先手必输
其次, 只有一条最长链, 先手和后手都会选在最长链上, 否则谁不在, 另一方直接获胜
在其 先手会在山峰, 否则后手直接卡死
故先手会选择在 最长链的最高端, 后手会选择最长链最远的地方, 保证和先手相隔 偶数个位置(保证两者都走最长链, 后手胜)
后手保证了先手最长链一定会输, 只能走最长链的反方向, 比较先手和后手能走的长度, 判断是否能先手赢
const int N = 1e5 + 5;int t, n, maxn, ans, a[N], p1[N], p2[N];int main() {scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d", a + i);p1[i] = (a[i] <= a[i - 1] || i == 1) ? 0 : (p1[i - 1] + 1);maxn = max(maxn, p1[i]);}for (int i = n; i >= 1; i--)p2[i] = (a[i] <= a[i + 1] || i == n) ? 0 : (p2[i + 1] + 1),maxn = max(p2[i], maxn);for (int i = 1; i <= n; i++)if (p1[i] == p2[i] && p1[i] == maxn && maxn > 0 && ((maxn & 1) == 0)) {ans = i;break;}for (int i = 1; i <= n; i++)if (ans != i && (p1[i] == maxn || p2[i] == maxn)) {ans = 0;break;}printf("%d", ans ? 1 : 0);}
