Codeforces Round 997 (Div. 2)
A. Shape Perimeter
题目大意
给你一个m*m的正方形,再给你n个坐标表示每次在xy移动的距离(第一个坐标是初始位置正方形左下角),问路径图形的周长
解题思路
记录好第一次的位置之后一直累加最后求总移动距离的差值即可
代码实现
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
std::cin >> t;
while (t--) {
int n, m;
std::cin >> n >> m;
std::vector<int> X = {0, 0}, Y = {0, 0};
for (int i = 0; i < n; i++) {
int x, y;
std::cin >> x >> y;
if (!X[0]) {
X[0] += x;
}
if (!Y[0]) {
Y[0] += y;
}
X[1] += x;
Y[1] += y;
}
std::cout << (X[1] + m - X[0] + Y[1] + m - Y[0]) * 2 << "\n";
}
}
B. Find the Permutation
题目大意
给你一个邻接矩阵g,求一个排列p,g满足
解题思路
代码实现
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::vector<std::string> g(n);
for (int i = 0; i < n; i++) {
std::cin >> g[i];
}
std::vector<int> p(n);
std::iota(p.begin(), p.end(), 0);
std::sort(p.begin(), p.end(), [&](int x, int y) {
if (g[x][y] == '1') {
return x < y;
} else {
return x > y;
}
});
for (int i = 0; i < n; i++) {
std::cout << p[i] + 1 << " \n"[i == n - 1];
}
}
}
C. Palindromic Subsequences
题目大意
给你一个数字n,请你构造一个长度为n的数组,满足数组中最长回文子序列长度大于n
解题思路
首先考虑最长长度为1和2,发现显然都不能满足,当长度为3的时候,如果两个相同的数字在外侧,则中间放x个不一样的数字就能对数量贡献x,也就是
代码实现
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::cout << "1 1 2 ";
for (int i = 3; i <= n - 3; i++) {
std::cout << i << " ";
}
std::cout << "1 2\n";
}
}
分类:
Codeforces
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具