Round A 2021 - Kick Start 2021
比赛链接:https://codingcompetitions.withgoogle.com/kickstart/round/0000000000436140
K-Goodness String (5pts, 7pts)
判断字符不同值,计算得分至K的差值
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int T;
cin >> T;
for (int i = 1; i <= T; ++i) {
int n, k, cnt = 0;
cin >> n >> k;
string s;
cin >> s;
for (int i = 0; i < n / 2; ++i)
if (s[i] != s[n - i - 1]) cnt++;
// cout << cnt << "\n";
if (cnt == k) cnt = 0;
else
cnt = abs(k - cnt);
cout << "Case #" << i << ": " << cnt << "\n";
}
return 0;
}
L Shaped Plots (8pts, 12pts)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int N, M, a[1005][1005], l[1005][1005], r[1005][1005], u[1005][1005],
d[1005][1005];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int T;
cin >> T;
for (int ca = 1; ca <= T; ca++) {
cin >> N >> M;
for (int i = 1; i <= N; ++i)
for (int j = 1; j <= M; ++j) cin >> a[i][j];
memset(l, 0, sizeof(l)), memset(r, 0, sizeof(r));
memset(u, 0, sizeof(u)), memset(d, 0, sizeof(d));
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++) {
if (a[i][j])
l[i][j] = l[i][j - 1] + 1, u[i][j] = u[i - 1][j] + 1;
}
int ret = 0;
for (int i = N; i > 0; i--)
for (int j = M; j > 0; j--)
if (a[i][j]) {
r[i][j] = r[i][j + 1] + 1, d[i][j] = d[i + 1][j] + 1;
// lu
ret += max(0, min(l[i][j], u[i][j] / 2) - 1);
ret += max(0, min(l[i][j], d[i][j] / 2) - 1);
ret += max(0, min(r[i][j], u[i][j] / 2) - 1);
ret += max(0, min(r[i][j], d[i][j] / 2) - 1);
ret += max(0, min(u[i][j], l[i][j] / 2) - 1);
ret += max(0, min(u[i][j], r[i][j] / 2) - 1);
ret += max(0, min(d[i][j], l[i][j] / 2) - 1);
ret += max(0, min(d[i][j], r[i][j] / 2) - 1);
}
cout << "Case #" << ca << ": " << ret << "\n";
}
return 0;
}
Rabbit House (9pts, 15pts)
BFS 搜索
// RioTian 21/03/22
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;
int dx[] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n, m, a[400][400], b[400][400];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int T;
cin >> T;
for (int i = 1; i <= T; ++i) {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) cin >> a[i][j];
memset(b, -1, sizeof(b));
priority_queue<pair<int, pair<int, int>>> h;
ll cnt = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
h.push(make_pair(a[i][j], make_pair(i, j)));
while (h.size()) {
auto t = h.top();
h.pop();
int x = t.second.first, y = t.second.second;
if (b[x][y] < 0) {
b[x][y] = t.first;
cnt += t.first - a[x][y];
for (int k = 0; k < 4; ++k) {
int nx = x + dx[k], ny = y + dy[k];
if (nx > 0 && nx <= n && ny > 0 && ny <= m &&
a[nx][ny] + 1 < b[x][y])
h.push(make_pair(t.first - 1, make_pair(nx, ny)));
}
}
}
cout << "Case #" << i << ": " << cnt << "\n";
}
return 0;
}
Checksum (10pts, 17pts, 17pts)
这道题没做出来。先记录一下dalao的解法
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int MAXN = 100005, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int N, M, a[505][505], b[505][505], ur[505], uc[505], fa[1005];
pair<int, int> c[505 * 505];
void init() {
scanf("%d", &N);
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++) scanf("%d", &a[i][j]);
M = 0;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++) {
scanf("%d", &b[i][j]);
if (b[i][j] > 0) {
c[++M] = make_pair(-b[i][j], (i - 1) * N + (j - 1));
}
}
for (int i = 1; i <= N; i++) scanf("%d", &ur[i]);
for (int i = 1; i <= N; i++) scanf("%d", &uc[i]);
}
int findSet(int x) {
if (!fa[x]) return x;
fa[x] = findSet(fa[x]);
return fa[x];
}
void work() {
memset(fa, 0, sizeof(fa));
sort(c + 1, c + M + 1);
int ret = 0;
for (int i = 1; i <= M; i++) {
int x = c[i].second / N + 1, y = c[i].second % N + 1 + N;
int bx = findSet(x), by = findSet(y);
if (bx != by) {
if (rand() % 2) fa[bx] = by;
else
fa[by] = bx;
} else
ret -= c[i].first;
}
printf("%d\n", ret);
}
int main() {
// freopen("d.in", "r", stdin), freopen("d.out", "w", stdout);
int T;
cin >> T;
for (int ca = 1; ca <= T; ca++) {
printf("Case #%d: ", ca);
init();
work();
}
return 0;
}
Round A 2021 - Kick Start 2021的更多相关文章
- [Kick Start] 2021 Round B
题目:Kick Start 2021 Round-B . Increasing Substring 输出字符串中每个字符的最长 Increasing Substring 的长度,非常简单的动态规划问题 ...
- [Kick Start] 2021 Round A
题目:2021 Round-A . K-Goodness String 签到题,计算当前字符串的 K-Goodness Score ,然后与给出的 K 做差即可. #include <iostr ...
- 郑政 | 2021软件代码开发技术作业四 | 需求改进&系统设计
需求改进&系统设计 -------------------------------------------------------------------------------------- ...
- GitHub Universe 2021|MS Reactor 邀你共聚年度盛会
GitHub Universe 2021 将于2021年10月27-28日(PDT)在线直播,MS Reactor 将与 CSDN 合作进行转播,与你一同观看这场全球开发者盛会. 关于 GitHub ...
- 2021 CSP-J复赛 我的备战与游记
目录 备战 2021.10.18 2021.10.19 2021.10.20 2021.10.21 2021.10.22 比赛当日 早上 线下见面 正文 比赛后 赛后总结与讲解 简单总结 Candy ...
- 议题征集令 | Apache DolphinScheduler Meetup 2021 来啦,议题征集正式开启!
点击上方 蓝字关注我们 社区的小伙伴们,经过精心筹备,我们很高兴地宣布,Apache DolphinScheduler Meetup 2021 将于 2021 年 11 月 27 日到来! 在 Mee ...
- Codeforces Round #697 (Div. 3)
A.Odd Divisor 题意:问一个数是不是含有奇数因子 思路:就直接给这个数循环除以2,看看最后剩下的数是不是0,如果不是就有奇数因子,如果是就没有 想不到:1)当时想着用log2来解决问题,后 ...
- (转)TCP注册端口号大全
分类: 网络与安全 cisco-sccp 2000/tcp Cisco SCCPcisco-sccp 2000/udp Cisco SCCp# Dan Wing <dwing&cisco ...
- unix & linux oralce用户 内存使用情况分析
Linux*********************************************************************************************** ...
- 网络-05-端口号-F5-负载均衡设-linux端口详解大全--TCP注册端口号大全备
[root@test1:Standby] config # [root@test1:Standby] config # [root@test1:Standby] config # [root@test ...
随机推荐
- IDEA安装与配置教程
一.下载并安装IDEA 1.下载 1.官网: 下载 IntelliJ IDEA (这里以Windows系统为例,其他系统类似) 2.安装 1.下载完成后,直接点击安装包安装,即可. 2.开始安装,然后 ...
- 构建一个语音转文字的WebApi服务
构建一个语音转文字的WebApi服务 简介 由于业务需要,我们需要提供一个语音输入功能,以便更方便用户的使用,所以我们需要提供语音转文本的功能,下面我们将讲解使用Whisper将语音转换文本,并且封装 ...
- 【UniApp】-uni-app-扩展组件
前言 好,经过上个章节的介绍完毕之后,了解了一下 uni-app-内置组件 那么了解完了uni-app-内置组件之后,这篇文章来给大家介绍一下 UniApp 中的扩展组件 首先不管三七二十一,先来新建 ...
- Educational Codeforces Round 26 Problem C
C. Two Seals time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- IntelliJ IDEA下载安装,以及关联gitee
https://www.jetbrains.com.cn/ 点击下载 IntelliJ IDEA Ultimate 旗舰版(收费) IntelliJ IDEA Community 社区版(免费) 安装 ...
- Asp .Net Core 集成 FluentValidation 强类型验证规则库
目录 入门程序 安装 案例:登录 验证器 内置验证器 自定义验证器 编写自定义验证器 可重复使用的属性验证器 本地化 DI 自动验证 官网:https://docs.fluentvalidation. ...
- cp {,bak}用法(转载)
cp filename{,bak} cp filename{,.bak} 这个命令是用来把filename备份成filename.bak的 等同于命令 cp filename filename.bak ...
- 5s!用浏览器打造一个开箱即用的Linux系统
做为Linux系统管理员.或者是系统运维工程师,肯定会在工作遇到这样的需求:需要开发环境.测试环境.准生产环境等等环境,有时候建一个环境费时间不说,还容易出各种错误,好不容易建好了,可能还用不了几天. ...
- Winform PictureBox图片旋转
Image img = this.pictureBox1.Image; img.RotateFlip(RotateFlipType.Rotate90FlipNone); this.pictureBox ...
- 文心一言 VS 讯飞星火 VS chatgpt (34)-- 算法导论5.3 1题
一.Marceau 教授不同意引理 5.5 证明中使用的循环不变式.他对第1次送代之前循环不变式是否为真提出质疑.他的理由是,我们可以很容易宣称一个空数组不包含0排列.因此一个空的子数组包含一个0排列 ...