比赛链接: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. Dubbo 就是靠它崭露头角!(身为开源框架很重要的一点)

    Hola,我是 yes. 经过了 RPC 核心和 Dubbo 微内核两篇文章后,今天终于要稍稍深入一波 Dubbo 了. 作为一个通用的 RPC 框架,性能是很重要的一环,而易用性和扩展性也极为重要. ...

  2. 基于vue2.x的webpack升级与项目搭建指南--基础篇

    first thing fitrst 博主声明:绝对不当标题党 有人看最好不过的背景: 十月初对公司产品的前端构建做了一些优化,但还遗留了不少问题(可了解我的前一篇博文:一次webpack小规模优化经 ...

  3. 简单的JS+CSS实现网页自定义换肤

     1,实现效果 2,实现原理 主要原理是利用css变量设置颜色,用js动态修改变量,使颜色变化,兼容性如下: 实现换肤之前先要了解一下伪类选择器 :root ,还有css的 var() 函数和 set ...

  4. zabbix自定义监控nginx

    nginx配置ngx_status 1.编译安装时带上--with-http_stub_status_module参数 2.vi nginx.conf location ~* ^/ngx_status ...

  5. show slave status常用参数备忘

    mysql> show slave status\G*************************** 1. row *************************** Slave_IO ...

  6. 【Oracle】translate函数用法解析

    转自:https://blog.csdn.net/shwanglp/article/details/52814173 基本语法: translate(string,from_str,to_str); ...

  7. 国人之光:大数据分析神器Apache Kylin

    一.简介 Apache Kylin是一个开源的.分布式的分析型数据仓库,提供Hadoop/Spark 之上的 SQL 查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由 eBay 开发并贡献 ...

  8. 屏蔽每分钟SSH尝试登录超过10次的IP

    屏蔽每分钟SSH尝试登录超过10次的IP 方法1:通过lastb获取登录状态: #!/bin/bash DATE=$(date +"%a %b %e %H:%M") #星期月天时分 ...

  9. 关于JDK15的简单理解

    一.为什么要了解JDK15? 2020年9月15日,Oracle官方发布了JDK15版本,及时关注官方的更新动态,可以让我们在日常开发中更合理的选择更加优秀的工具方法,避免使用一些过时的或一些即将被删 ...

  10. Django中多表关联的展示问题:

    增加一个知识点,当表中有多对多关联时,在前端展示的时候是一个列表,所以在展示的时候需要这样做: 表结构: class ProjectEnv(models.Model): project = model ...