比赛链接:https://codeforces.com/contest/1438

A. Specific Tastes of Andre

题意

构造一个任意连续子数组元素之和为子数组长度倍数的数组。

题解

构造全为同一值的任意数组即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << 1 << " \n"[i == n - 1];
}
}
return 0;
}

B. Valerii Against Everyone

题意

给出一个大小为 \(n\) 的数组 \(b\) , \(a_i = 2^{b_i}\) ,判断数组 \(a\) 中是否存在和相同的两个不相交的连续子数组。

题解

判断 \(b\) 中是否有一个数出现了两次即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
map<int, int> mp;
bool ok = false;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (++mp[x] == 2) ok = true;
}
cout << (ok ? "YES" : "NO") << "\n";
}
return 0;
}

C. Engineer Artem

题意

给出一个 \(n \times m\) 的矩阵,给其中一些元素加一使得不存在两个相邻元素相等。

题解

像国际象棋棋盘那样把每个数的奇偶性对应到相应的黑白格即可。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int a;
cin >> a;
cout << a + (a % 2 != (i + j) % 2) << " \n"[j == m - 1];
}
}
}
return 0;
}

D. Powerful Ksenia

题意

给出一个大小为 \(n\) 的数组 \(a\) ,每次操作如下:

  • 选择三个不同的下标 \(i,\ j,\ k\)
  • \(a_i = a_j = a_k = a_i \oplus a_j \oplus a_k\)

问能否在 \(n\) 次操作内将 \(a\) 中 \(n\) 个元素变为同一值,如果可以,给出操作过程。

题解

  • \(n\) 为奇数的话正反各来一遍即可,由于最后两个数不能作为起点,所以共需 \(n - 2\) 次操作。
  • \(n\) 为偶数的话需要判断前 \(n - 1\) 个数的异或和是否等于第 \(n\) 个数,即 \(n\) 个数的异或和是否为 \(0\) ,如果等于,去掉第 \(n\) 个数即为和奇数相同的情况。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
if (n & 1) {
cout << "YES" << "\n";
cout << n - 2 << "\n";
for (int i = 1; i + 2 <= n; i += 2) cout << i << ' ' << i + 1 << ' ' << i + 2 << "\n";
for (int i = n - 4; i >= 1; i -= 2) cout << i << ' ' << i + 1 << ' ' << i + 2 << "\n";
} else {
int xor_sum = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
xor_sum ^= a;
}
if (xor_sum != 0) {
cout << "NO" << "\n";
} else {
--n;
cout << "YES" << "\n";
cout << n - 2 << "\n";
for (int i = 1; i + 2 <= n; i += 2) cout << i << ' ' << i + 1 << ' ' << i + 2 << "\n";
for (int i = n - 4; i >= 1; i -= 2) cout << i << ' ' << i + 1 << ' ' << i + 2 << "\n";
}
}
return 0;
}

Codeforces Round #682 (Div. 2)【ABCD】的更多相关文章

  1. Codeforces Round #678 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1436 A. Reorder 题解 模拟一下这个二重循环发现每个位置数最终都只加了一次. 代码 #include <bi ...

  2. Codeforces Round #676 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...

  3. Codeforces Round #675 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...

  4. Codeforces Round #668 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...

  5. Codeforces Round #732 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1546 A. AquaMoon and Two Arrays 题意 给出两个大小为 \(n\) 的数组 \(a, b\) ,每 ...

  6. Codeforces Round #677 (Div. 3)【ABCDE】

    比赛链接:https://codeforces.com/contest/1433 A. Boring Apartments 题解 模拟即可. 代码 #include <bits/stdc++.h ...

  7. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  8. Codeforces Round #684 (Div. 2)【ABC1C2】

    比赛链接:https://codeforces.com/contest/1440 A. Buy the String 题解 枚举字符串中 \(0\) 或 \(1\) 的个数即可. 代码 #includ ...

  9. Codeforces Round #658 (Div. 2)【ABC2】

    做完前四题还有一个半小时... 比赛链接:https://codeforces.com/contest/1382 A. Common Subsequence 题意 给出两个数组,找出二者最短的公共子序 ...

随机推荐

  1. #2020征文-开发板# 用鸿蒙开发AI应用(二)系统篇

    目录: 前言 安装虚拟机 安装 Ubuntu 设置共享文件夹 前言上回说到,我们在一块 HarmonyOS HiSpark AI Camera 开发板,并将其硬件做了一下解读和组装.要在其上编译鸿蒙系 ...

  2. Angular入门到精通系列教程(10)- 指令(Directive)

    1. 摘要 2. 组件与指令之间的关系 2.1. 指令的种类 3. Angular 中指令的用途 4. 指令举例 4.1. 指令功能 4.2. Anuglar CLI生成基本文件 4.3. Direc ...

  3. 实现一个简单的 Linux Shell(C++)

    Implement a simple command interpreter in Linux. The interpreter should: support both internal and e ...

  4. C#中的异步和多线程

    许多开发人员对异步代码和多线程以及它们的工作原理和使用方法都有错误的认识.在这里,你将了解这两个概念之间的区别,并使用c#实现它们. 我:"服务员,这是我第一次来这家餐厅.通常需要4个小时才 ...

  5. MongoDB Sharding(二) -- 搭建分片集群

    在上一篇文章中,我们基本了解了分片的概念,本文将着手实践,进行分片集群的搭建 首先我们再来了解一下分片集群的架构,分片集群由三部分构成: mongos:查询路由,在客户端程序和分片之间提供接口.本次实 ...

  6. ctfhub技能树—信息泄露—备份文件下载—vim缓存

    打开靶机 查看页面信息 在使用vim时会创建临时缓存文件,关闭vim时缓存文件则会被删除,当vim异常退出后,因为未处理缓存文件,导致可以通过缓存文件恢复原始文件内容 以 index.php 为例:第 ...

  7. 阿里云 RTC QoS 屏幕共享弱网优化之若干编码器相关优化

    屏幕共享是视频会议中使用频率最高的功能之一,但在实际场景中用户所处网络环境复杂,常遇到丢包或者拥塞的情况,所以如何优化弱网环境下的用户体验也成为了音视频通信中重要的一环.本文主要分享阿里云 RTC Q ...

  8. ALV中的fieldcat详解

    字段目录是用来控制ALV显示的网格中每个字段的属性的,比如字段的顺序,对齐方式,可编辑状态,颜色,等等.常用的字段如下: Row_pos:    默认值为0,可选值为1.2.3,既最大分3级别显示 c ...

  9. Nginx报504 gateway timeout错误的解决方法(小丑搞笑版。。。)

    一.今天登录我的网站,突然发现报了下面的一个错误: 我的第一反应是:超时了应该是Nginx代理没有设置超时时间,默认的超时时间估计太小了,然后就按照正常的方式用Xshell连接服务器,应该是网络或者是 ...

  10. secrets 管理工具 Vault 的介绍、安装及使用

    原文:https://ryan4yin.space/posts/expirence-of-vault/ Vault 是 hashicorp 推出的 secrets 管理.加密即服务与权限管理工具.它的 ...