补题链接: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

题意:是否能把字符串中的 ? 替换为 10 使得字符串为回文串。

注意点:长度为奇数时,如果中点是 ? 则提前处理掉

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的更多相关文章

  1. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  2. Codeforces Round #590 (Div. 3) Editorial

    Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...

  3. Codeforces Round #747 (Div. 2) Editorial

    Codeforces Round #747 (Div. 2) A. Consecutive Sum Riddle 思路分析: 一开始想起了那个公式\(l + (l + 1) + - + (r − 1) ...

  4. 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 ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. redis基础命令复习(Sring,Hash,List,Set,SortedSet)

    1,Redis数据结构: https://redis.io/commands 2,Redis命令---Redis通用命令(常见的有,keys,del,exists,expire,ttl) 2.1,ke ...

  2. 深入了解MD5加密技术及其应用与局限

    一.MD5简介 MD5(Message Digest Algorithm 5)是一种单向散列函数,由美国密码学家罗纳德·李维斯特(Ronald Linn Rivest)于1991年发明.它主要用于将任 ...

  3. IDEA提示java_ 程序包org.apache.ibatis.session不存在

    一.解决方案 1.问题原因: 这是因为配置Java的程序包这块出现了错误,同时可能你还没有设置让IDEA自动加载Jar包,才会报出这种错误的. 2.解决方案: 解决方式如下: File->Set ...

  4. ACPM高效C++组件管理让音视频终端SDK性能更好、稳定性更高

    本专栏将分享阿里云视频云MediaBox系列技术文章,深度剖析音视频开发利器的技术架构.技术性能.开发能效和最佳实践,一起开启音视频的开发之旅.本文为MediaBox技术架构篇,重点从 ACPM介绍. ...

  5. [ARC144D] AND OR Equation

    Problem Statement You are given positive integers $N$ and $K$. Find the number, modulo $998244353$, ...

  6. [CF1748E] Yet Another Array Counting Problem

    题目描述 The position of the leftmost maximum on the segment $ [l; r] $ of array $ x = [x_1, x_2, \ldots ...

  7. Python实现贪吃蛇大作战

    贪吃蛇 初始版本 初始版本,只存在基本数据结构--双向队列. 游戏思路 贪吃蛇通过不断得吃食物来增长自身,如果贪吃蛇碰到边界或者自身则游戏失败. 食物是绿色矩形来模拟,坐标为随机数生成,定义一个蛇长变 ...

  8. 数字孪生和GIS结合能为智慧社区带来怎样的改变?

    数字孪生和地理信息系统(GIS)是当今智慧社区发展中的两个重要技术,它们的结合将为智慧社区带来根本性的改变和巨大的发展机遇.这种结合将深刻影响社区的规划.建设.运营和管理,为居民创造更智能.便利.宜居 ...

  9. 你是否想知道如何应对高并发?Go语言为你提供了答案!

    并发编程是当前软件领域中不可忽视的一个关键概念.随着CPU等硬件的不断发展,我们都渴望让我们的程序运行速度更快.更快.而Go语言在语言层面天生支持并发,充分利用现代CPU的多核优势,这也是Go语言能够 ...

  10. 云MSP技本功|redis的5种对象与8种数据结构之字符串对象(下)

    简介: 引言 本文是对<redis设计与实现(第二版)>中数据结构与对象相关内容的整理与说明.本篇文章只对对象结构,1种对象--字符串对象.以及字符串对象所对应的两种编码--raw和emb ...