Codeforces Round #713 (Div. 3) Person Editorial
补题链接:Here
1512A - Spy Detected!
题意:找到唯一不同数的下标
复制数组然后比较 \(a_1\)
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _;
for (cin >> _; _--;) {
int n;
cin >> n;
vector<int> v(n);
for (int &e : v) {
cin >> e;
}
vector<int> a = v;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if (v[i] != a[1]) {
cout << i + 1 << "\n";
}
}
}
return 0;
}
1512B - Almost Rectangle
题意:给定 \(n \times n\) 的. 和 * 坐标图,* 仅两个找到对称位置使 4 个 * 构成矩阵
分别考虑 同行、同列、不同行同列
struct node {
int x, y;
};
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _;
for (cin >> _; _--;) {
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<node> star;
bool f = false;
for (int i = 0; i < n && !f; ++i)
for (int j = 0; j < n && !f; ++j) {
if (a[i][j] == '*') {
star.push_back({i, j});
}
if (star.size() == 2) f = true;
}
// 同行
if (star[0].x == star[1].x) {
if (star[0].x + 1 < n) {
a[star[0].x + 1][star[0].y] = '*';
a[star[1].x + 1][star[1].y] = '*';
} else {
a[star[0].x - 1][star[0].y] = '*';
a[star[1].x - 1][star[1].y] = '*';
}
} else if (star[0].y == star[1].y) { // 同列
if (star[0].y + 1 < n) {
a[star[0].x][star[0].y + 1] = '*';
a[star[1].x][star[1].y + 1] = '*';
} else {
a[star[0].x][star[0].y - 1] = '*';
a[star[1].x][star[1].y - 1] = '*';
}
} else {
a[star[0].x][star[1].y] = '*';
a[star[1].x][star[0].y] = '*';
}
for (int i = 0; i < n; ++i) {
cout << a[i] << "\n";
}
}
return 0;
}
1512C - A-B Palindrome
题意:是否能把字符串中的 ? 替换为 1 或 0 使得字符串为回文串。
注意点:长度为奇数时,如果中点是
?则提前处理掉
AC 代码:
string solve() {
int a, b;
string s;
cin >> a >> b >> s;
int n = a + b;
for (int i = 0; i < s.size(); i++)
if (s[i] == '1' && s[n - 1 - i] == '0')
return "-1";
for (int i = 0; i < s.size(); i++)
if (s[i] == '?')
s[i] = s[n - 1 - i];
if (n % 2 && s[n / 2] == '?')
if (a % 2)
s[n / 2] = '0';
else
s[n / 2] = '1';
for (char c : s)
if (c == '0')
a--;
else if (c == '1')
b--;
if (a % 2 || b % 2 || a < 0 || b < 0)
return "-1";
for (int i = 0; i < s.size(); i++)
if (s[i] == '?')
if (a)
s[i] = s[n - 1 - i] = '0', a -= 2;
else
s[i] = s[n - 1 - i] = '1', b -= 2;
return s;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _;
for (cin >> _; _--;) {
cout << solve() << "\n";
}
return 0;
}
1512D - Corrupted Array
\(b\) 中所有元素的总和是多少? 这是 \(a + x\) 中所有元素之和的两倍。
用 \(B\) 表示 \(b\) 的所有元素的总和。 让我们迭代添加哪些数组元素作为元素 \(a\) 的总和(以 \(a\) 表示)。 然后,\(x = B-2⋅A\)。 剩下的要检查的是元素 \(x\) 是否存在于数组 \(b\) 中
上面的思路可以使用哈希表或二进制搜索树来完成。
using ll = long long;
void solve() {
int n;
cin >> n;
vector<ll> b(n + 2);
for (int i = 0; i < n + 2; i++)
cin >> b[i];
sort(b.begin(), b.end());
ll sum = 0;
for (int i = 0; i <= n; i++)
sum += b[i];
for (int i = 0; i <= n; i++) {
if (sum - b[i] == b.back() || sum - b[i] == b[i]) {
for (int j = 0; j <= n; j++) {
if (j != i)
cout << b[j] << " ";
}
cout << "\n";
return;
}
}
cout << "-1\n";
}
Codeforces Round #713 (Div. 3) Person Editorial的更多相关文章
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #590 (Div. 3) Editorial
Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...
- Codeforces Round #747 (Div. 2) Editorial
Codeforces Round #747 (Div. 2) A. Consecutive Sum Riddle 思路分析: 一开始想起了那个公式\(l + (l + 1) + - + (r − 1) ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
随机推荐
- 【Servlet】两种配置
web.xml中Servlet的注解 <servlet> <!-- servlet的内部名称,⾃定义 --> <servlet-name>类名</servle ...
- 如何修改Ubuntu的时间与时间同步
1.安装ntpdate,同步标准时间 zce@ubuntu:~$ sudo apt install ntpdate 输入管理员密码确认安装 zce@ubuntu:~$ sudo apt install ...
- socket链接和发送demo
Socker 包是创建客户端的,用于链接服务器: ServerSocket 包是创建服务器的,启动端口进行监听等待链接 socket客户端-----------------java.lang.Stri ...
- Rong晔大佬教程学习(2):取指
1.rvseed_defines.v(定义了一些参数,没有实际意义) 该文件定义了一些基本参数,在后续的代码中都会调用该文件 // simulation clock period `define SI ...
- video和表单组件(不常用 类型太少)
h5不能自动播放,只有在静音的前提下才能 button:(种类太少 不能满足需求) <button size="mini" type="primary" ...
- C++学习笔记六:运算符(五种基本运算操作,优先级和结合性)
这一章对操作符进行简单的总结: 1.五种基本运算类型:加减乘除,取余 add, substract, multiply, divide, modulus int number1{2}; int num ...
- 3D 高斯喷溅 🤗 为什么图形永远不会相同
高斯喷溅 (Gaussian Splatting) 技术是一种翻天覆地的渲染手段,能够以 144 帧每秒的速度渲染出高质量的场景,这和传统的图形处理流程截然不同 这种将高斯数据转换成图像的过程,与训练 ...
- [CSP-S 2023] 密码锁
题目描述 小 Y 有一把五个拨圈的密码锁.如图所示,每个拨圈上是从 \(0\) 到 \(9\) 的数字.每个拨圈都是从 \(0\) 到 \(9\) 的循环,即 \(9\) 拨动一个位置后可以变成 \( ...
- 【Python微信机器人】第六七篇: 封装32位和64位Python hook框架实战打印微信日志
目录修整 目前的系列目录(后面会根据实际情况变动): 在windows11上编译python 将python注入到其他进程并运行 注入Python并使用ctypes主动调用进程内的函数和读取内存结构体 ...
- Windows下使用C#和32feet.NET开发蓝牙传输功能的记录
引用的第三方Nuget库 32feet.NET 3.5.0 MaterialDesignColors MaterialDesignThemes Newtonsoft.Json 使用到的技术: XAML ...