Codeforces Round #658 (Div. 2)【ABC2】
做完前四题还有一个半小时...
比赛链接:https://codeforces.com/contest/1382
A. Common Subsequence
题意
给出两个数组,找出二者最短的公共子序列。
题解
最短即长为一。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n, m; cin >> n >> m;
set<int> a, b;
for (int i = 0; i < n; ++i) {
int x; cin >> x;
a.insert(x);
}
for (int i = 0; i < m; ++i) {
int x; cin >> x;
b.insert(x);
}
for (auto i : a) {
if (b.count(i)) {
cout << "YES" << "\n";
cout << 1 << ' ' << i << "\n";
return;
}
}
cout << "NO" << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
B. Sequential Nim
题意
给出 $n$ 堆石子的数量,两人轮流从最左端的非空堆中取任意数量的石子,无法再取者判负,判断游戏的胜者。
题解
第一次取到数量大于 $1$ 的石子堆的人获胜。
证明
将石子堆分为两类:连续的数量 $>1$ 的和单独的数量 $=1$ 的,第一次取到数量大于 $1$ 的石子堆的人可以通过取得剩一个或全部取完来迫使对方进入自己的节奏。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int get_non_one = -1;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
if (x > 1 and get_non_one == -1) get_non_one = i;
}
if (get_non_one == -1) {
cout << (n & 1 ? "First" : "Second") << "\n";
} else {
cout << (get_non_one & 1 ? "First" : "Second") << "\n";
}
} int main() {
int t; cin >> t;
while (t--) solve();
}
C2. Prefix Flip (Hard Version)
题意
每次可以选取二进制串的前 $p$ 位全部取反然后反转,输出将二进制串 $a$ 变为 $b$ 的任一方案。
题解
先从前向后将 $a$ 的前缀合并为单一字符,然后从后向前操作与 $b$ 的不同位。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
string a, b; cin >> a >> b;
vector<int> p;
for (int i = 1; i < n; ++i) {
if (a[i] != a[i - 1]) {
p.push_back(i);
}
}
char now = a.back();
for (int i = n - 1; i >= 0; --i) {
if (now != b[i]) {
p.push_back(i + 1);
now = (now == '0' ? '1' : '0');
}
}
cout << p.size() << ' ';
for (int i : p) cout << i << ' ';
cout << '\n';
} int main() {
int t; cin >> t;
while (t--) solve();
}
Codeforces Round #658 (Div. 2)【ABC2】的更多相关文章
- Codeforces Round #677 (Div. 3)【ABCDE】
比赛链接:https://codeforces.com/contest/1433 A. Boring Apartments 题解 模拟即可. 代码 #include <bits/stdc++.h ...
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- Codeforces Round #684 (Div. 2)【ABC1C2】
比赛链接:https://codeforces.com/contest/1440 A. Buy the String 题解 枚举字符串中 \(0\) 或 \(1\) 的个数即可. 代码 #includ ...
- Codeforces Round #682 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1438 A. Specific Tastes of Andre 题意 构造一个任意连续子数组元素之和为子数组长度倍数的数组. ...
- Codeforces Round #678 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1436 A. Reorder 题解 模拟一下这个二重循环发现每个位置数最终都只加了一次. 代码 #include <bi ...
- Codeforces Round #676 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...
- Codeforces Round #675 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...
- Codeforces Round #668 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...
- Codeforces Round #732 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1546 A. AquaMoon and Two Arrays 题意 给出两个大小为 \(n\) 的数组 \(a, b\) ,每 ...
随机推荐
- 【函数分享】每日PHP函数分享(2021-1-12)
str_pad() 使用另一个字符串填充字符串为指定长度 . string str_pad ( string $input, int $pad_length[, string $pad_string= ...
- 浅谈JVM垃圾回收
JVM内存区域 要想搞懂啊垃圾回收机制,首先就要知道垃圾回收主要回收的是哪些数据,这些数据主要在哪一块区域. Java8和Java8之前的相同点有很多. 都有虚拟机栈,本地方法栈,程序计数器,这三个是 ...
- mac配置Android SDK
下载地址:http://tools.android-studio.org/index.php/sdk 2.找到tools文件夹 选中android-sdk-macosx包下的tools文件夹,按com ...
- kubernets之存活探针
一 存活探针存在的意义 1.1 kubernet通过存活探针(liveness probe)检查容器是否还在运行,可以为pod中的每个容器单独指定存活探针,如果探针执行失败,kubernets会 ...
- 奇技淫巧,还是正统功夫? - Python推导式最全用法
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取 python免费学习资 ...
- misc刷题
前言:听说misc打得好,头发多不了 kali自带的字典: cd /usr/share/wordlists/ 字典网站:http://contest-2010.korelogic.com/wordli ...
- [GKCTF2020]老八小超市儿
题目来自buu 一.题目初探 首先是一个shopxo搭建的演示站,通过扫描后台得到如下的网页 二.题目解答 首先是找到后台登陆的admin.php,然后通过百度找到shopxo的默认管理员登陆账号和密 ...
- AmoebaNet:经费在燃烧,谷歌提出基于aging evolution的神经网络搜索 | AAAI 2019
论文提出aging evolution,一个锦标赛选择的变种来优化进化算法,在NASNet搜索空间上,对比强化学习和随机搜索,该算法足够简洁,而且能够更快地搜索到更高质量的模型,论文搜索出的Amoeb ...
- oracle RAC和RACOneNode之间的转换
Convert RAC TO RACOneNode 1.查看资源状态 [grid@rac01 ~]$ crsctl status res -t 从这里看到,数据库的名字叫racdb 2.查看实例 [o ...
- Array.of使用实例
Array.of是es6新增的API,其实粗暴点理解,光看of,就可以猜到它是数组的意思,所以猜测可以用来把字符串转换成数组. 像这样的table,有批量删除和单个删除的功能,,但是又不想写两个方法, ...