比赛链接: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. ORA-39700: database must be opened with UPGRADE option【转】

    1. 错误 数据库升级后(从11.2.0.1升级到11.2.0.4)启动报错 SQL> startup ORACLE instance started.   Total System Globa ...

  2. 详解线程池的作用及Java中如何使用线程池

    服务端应用程序(如数据库和 Web 服务器)需要处理来自客户端的高并发.耗时较短的请求任务,所以频繁的创建处理这些请求的所需要的线程就是一个非常消耗资源的操作.常规的方法是针对一个新的请求创建一个新线 ...

  3. vue-vite浅析

    大家好,我是小雨小雨,致力于分享有趣的.实用的文章. 内容分为原创和翻译,如果有问题,欢迎随时评论或私信,很乐意和大家一起探讨,一起进步. 分享不易,希望能够得到大家的支持和关注. vite出了好久了 ...

  4. python 2.7.11 环境安装

    0  安装依赖: yum install zlib zlib-devel readline-devel sqlite-devel bzip2-devel openssl-devel gdbm-deve ...

  5. JS navigator.userAgent

    var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > - ...

  6. 【Redis】Redis基础 - Redis安装启动测试

    Redis基本 - 安装 文章目录 Redis基本 - 安装 Linux下安装Redis Docker 方式 Github 源码编译方式 直接安装方式 Windows下Redis安装 记录 - Red ...

  7. oracle字符集与乱码(转)

    作者:hcling97    http://blog.sina.com.cn/hcling97 2013年5月15日 转载请注明出处 字符集问题一直叫人头疼,究其原因还是不能完全明白其运作原理. 在整 ...

  8. .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx)

    在.NET Core部署到linux(CentOS)最全解决方案,常规篇一文,我们详细讲解了传统的.NET Core部署到Linux服务器的方法,学到了Linux在虚拟机下的安装.Xshell,Xft ...

  9. 人工智能"眼睛"——摄像头

    摄像头机器视觉人工智能的"眼睛",其重要性在嵌入式领域不言而喻.但是如何理解和使用摄像头却是一个非常棘手的问题.本文主要针对调试摄像头过程中遇到的问题,对摄像头的基本原理及概述进行 ...

  10. mybatis源码解析之架构理解

    mybatis是一个非常优秀的开源orm框架,在大型的互联网公司,基本上都会用到,而像程序员的圣地-阿里虽然用的是自己开发的一套框架,但其核心思想也无外乎这些,因此,去一些大型互联网公司面试的时候,总 ...