比赛链接: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;
}

最新文章

  1. Reactjs+Webpack+es2015 入门HelloWord(一)
  2. linux中终端控制键Ctrl+C,Ctrl+Z,Ctrl+D的使用场合
  3. BeanUtils.populate的作用
  4. c# long转 datetime
  5. Android 天气曲线
  6. mysql的事务和select...for update
  7. HTML5视频标签video
  8. 清除number输入框的上下箭头
  9. Restful中 @RequestParam,@PathParam,@PathVariable等注解区别
  10. gitlab-ci.xml:script config should be a string or an array of strings
  11. 负载均衡(nginx、dubbo、zookeeper)
  12. SQL的decode()函数
  13. 收藏 —— 教你阅读Python开源项目
  14. Java学习笔记之——类与对象
  15. MVCmoduleExample.html
  16. android-------Android Studio使用MAT分析工具遇到的错误
  17. 转-[WebServer] Windows操作系统下 Tomcat 服务器运行 PHP 的环境配置
  18. AJAX 与 Python 后台通信
  19. java 数据结构与算法---栈
  20. java线程的一些基础小知识

热门文章

  1. Lesson_strange_words4
  2. 【渲染教程】使用3ds Max和ZBrush制作卡通风格的武器模型(上)
  3. Writing in the science: Introducion
  4. (二)React Ant Design Pro + .Net5 WebApi:前端环境搭建
  5. 【windows】快捷键
  6. 什么是xss攻击
  7. Centos6.9安装ACFS
  8. Core3.1 微信v3 JSAPI支付
  9. 1.8V转5V电平转换芯片,1.8V转5V的电源芯片
  10. HTTP协议相关知识整理: