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 ...
随机推荐
- Modbus转Profinet 网关
产品简介 实现 PROFINET 网络与串口网络之间的数据通信,三个串口可分别连接具有 RS232 或 RS485 接口的设 备到 PROFINET 网络.即将串口设备转换为 PROFINET 设备. ...
- CentOS(7.6)环境下迁移Mysql(5.7)的data目录到指定位置
第一步:关闭Mysql #关闭Mysql服务systemctl stop mysqld#查看Mysql服务状态 ps -ef|grep mysql 第二步:创建新目录,并拷贝数据文件 #创建data文 ...
- 使用nacos配置无效,原因:项目中 gateway服务配置的 application的name:@artifactId@ 和nacos上配置的DataID 不一致导致
遇到一个问题,项目启动后一致无法正常登陆进入后端,登陆时一直报错返回null,排查后发现是自己粗心,项目中 gateway服务配置的 application的name:@artifactId@ 和 ...
- Java如何连接Mysql数据库
条件:eclipse.MySQL .jdbc驱动 eclipse.MySQL 的安装.下载jdbc连接驱动 eclipse的安装去官网下载并安装 MySQL .jdbc的下载地址请访问:https:/ ...
- Celery将任务分发到不同的队列,交给不同的Worker处理
https://docs.celeryq.dev/en/stable/userguide/routing.html#routing-tasks https://blog.csdn.net/wangle ...
- 【1】从零玩转OSS阿里云存储服务之阿里云平台等操作-1-cong-ling-wan-zhuan-oss-a-li-yun-cun-chu-fu-wu-zhi-a-li-yun-ping-tai-deng-cao-zuo
title: [1]从零玩转OSS阿里云存储服务之阿里云平台等操作 date: 2021-06-09 17:21:12.037 updated: 2021-12-26 17:43:18.92 url: ...
- Odoo16—国际化翻译
开发odoo系统模块的时候,如果一开始就有国际化的需求,无论是模型的定义还是视图的构建,建议使用英语作为第一语言:一方面,英语本身就是一种国际化的语言:另一方面,odoo内置模型字段描述如Create ...
- Python——第一章:循环语句while
循环语句可以让我们的代码重复的去执行 while循环: while 条件: 代码 过程: 判断while循环的条件是否为真, 如果真, 执行代码. 然后再次判断条件.....直到条件为假 ...
- SQL优化案例(1):隐式转换
MySQL是当下最流行的关系型数据库之一,互联网高速发展的今天,MySQL数据库在电商.金融等诸多行业的生产系统中被广泛使用. 在实际的开发运维过程中,想必大家也常常会碰到慢SQL的困扰.一条性能不好 ...
- BUUCTF 加固题 Ezsql WriteUp
文章目录 想直接要加固代码的点这里 题目 一.查看 二.进入目标机器加固 修改前的文件: 添加如下代码: 修改后的文件 三.Check 想直接要加固代码的点这里 题目 靶机地址解释: 第一行:目标机器 ...