Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2) (个人题解)
Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)
A. Prison Break
https://codeforces.com/contest/1457/problem/A
题意:给定一个n行m列的监狱(每个(i,j)中均有犯人),犯人们为了集体逃脱找到了一个洞口(r,c)点。现在请问最少需要多少秒才能全体逃脱。
思路:只要计算一下边角的犯人离出口的最大距离即可
void solve() {
int n, m, r, c;
cin >> n >> m >> r >> c;
cout << max(r - 1, n - r) + max(c - 1, m - c) << endl;
}
B. Repainting Street
https://codeforces.com/contest/1457/problem/B
题意:Tom要为一排房子粉刷颜色,每个房子的都有它的颜色,由于Tom认为相同颜色的为”美丽“,但Tom每天只能为k个连续的房子进行粉刷。请问最少需要多少天才能变美丽
思路:由于仅100种颜色,可以使用暴力枚举 + 滑动窗口解决
void solve() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 0; i < n; ++i)
cin >> a[i];
int res = n;
for (int c = 1; c <= 100; ++c) { //枚举进行粉刷的颜色种类
int last = -k, curr = 0;
for (int j = 0; j < n; ++j) {
if (a[j] == c)
continue;
if (last + k <= j) {
last = j;
curr++;
}
}
res = min(res, curr);
}
printf("%d\n", res);
}
C. Bouncing Ball
https://codeforces.com/contest/1457/problem/C
string s;
void solve() {
int n, p, k, x, y;
cin >> n >> p >> k;
p--;
vector<int> b(n);
cin >> s;
cin >> x >> y;
int ans = 1 << 30;
for (int i = n - 1; 0 <= i; --i) {
b[i] = !(s[i] == '1');
if (i + k < n)
b[i] += b[i + k];
if (i >= p)
ans = min(ans, (i - p) * y + b[i] * x);
}
printf("%d\n", ans);
}
E. New Game Plus!
https://codeforces.com/contest/1457/problem/E
理解好题意,利用前缀和贪心即可
// Author : RioTian
// Time : 20/11/29
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 5;
int n, k, a[N];
ll b[N], sum, res = -(1LL << 60), curr;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) {
b[i] = b[i - 1] + a[i];
sum += 1LL * (i - 1) * a[i];
}
for (int i = 1; i <= n; ++i) {
int mx = (i - 1 + k) / (k + 1), mn = (i - 1) / (k + 1);
res = max(res, (b[n] - b[i - 1]) * mx + curr + sum);
sum -= (b[n] - b[i]);
curr += 1LL * mn * a[i];
}
res = max(res, curr);
cout << res << endl;
return 0;
}
分类:
刷题笔记: CF
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战