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 ...
随机推荐
- Django笔记四十三之使用uWSGI部署Django系统
本文首发于公众号:Hunter后端 原文链接:Django笔记四十三之使用uWSGI部署Django系统 目前部署 Django 的方式一般来说是使用 Nginx + uWSGI + Django 来 ...
- 【结对作业】第一周 | 学习体会day06
初步做了app的页面 change作为mysql的关键字,不可以作为命名,否则报错 做了两条线路的中转 初步学习了frame标签,打算明天实现页面的部分切换
- javaweb项目搭建|前端项目【包含增删改查,mysql】二
首先,新建一个javaweb项目[前提已经下载tomcat,mysql,此实验idea版本为2022,其他版本可能位置不一样] File->New->Project 起一个项目名称(随便起 ...
- Java+Selenium爬取高德POI边界坐标
一.写在前面 关于爬取高德兴趣点边界坐标网上有几篇文章介绍实现方式,总的来说就是通过https://www.amap.com/detail/get/detail传入POI的ID值获取数据,BUT,如果 ...
- tomact
常见的java相关的web服务器软件: *webLogic:oracle公司,大型的JavaEE服务器,支持所有的JavaEE规范,收费. *webSphere:IBM公司,大型的JavaEE ...
- Redis入门实践
安装Redis 下载:官网:https://redis.io/download/,选择稳定版下载. 上传至linux 解压Redis:tar -zxvf redis-6.2.7.tar.gz,得到: ...
- 云端开炉,线上训练,Bert-vits2-v2.2云端线上训练和推理实践(基于GoogleColab)
假如我们一定要说深度学习入门会有一定的门槛,那么设备成本是一个无法避开的话题.深度学习模型通常需要大量的计算资源来进行训练和推理.较大规模的深度学习模型和复杂的数据集需要更高的计算能力才能进行有效的训 ...
- The second day learning summary
1.什么是接口测试? 接口测试是测试系统组件间接口的一种测试.接口测试主要用于外部系统与系统之间以及内部各个子系统之间的交互点,定义特定的交互点,然后通过这些交互点来,通过一些特殊的规则也就是协议,来 ...
- nginx下的proxy_pass使用
之前的文章说到了,return,rewrite的使用,以及它们的使用场景,今天再来说一种代理的使用,proxy_pass,它属于nginx下的ngx_http_proxy_module模块,没有显示的 ...
- pytest框架学习-前置和后置setup和teardown
前置和后置 (1)setup和teardown,方法级 写在类中 方法级,每个用例都会执行setup和teardown. 相当于setup_method和teardown_method (2)setu ...