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\) ,每 ...
随机推荐
- Lesson_strange_words4
mount on 安装 arc 弧 actuator 马达,致动器:调节器 roughly 大致,大约 radially 径向,放射状 stepper 步进机 motor 电机,发动机 sequent ...
- 在mapper.xml映射文件中添加中文注释报错
问题描述: 在写mapper.xml文件时,想给操作数据库语句添加一些中文注释,添加后运行报如下错误: 思考 可能是写了中文注释,编译器在解析xml文件时,未能成功转码,从而导致乱码.但是文件开头也采 ...
- Java高并发与多线程(一)-----概念
其实之前一直想专门写一篇,单独说一说Java的多线程与高并发,但是一直以来,都没有想到能够用什么比较有趣的表现形式去表达出来,而且网上充斥着很多类似的博客,有好的又不好的,有简介的有繁琐的,所以也一直 ...
- ACL技术(访问控制列表)
• Access Control List • 访问控制列表 • 是一种包过滤技术 • ACL基于IP包头的IP地址.四层TCP/UDP头部的端口号.[五层数据]进行过滤 • ...
- 【JavaWeb】JSTL 标签库
JSTL 标签库 简介 JSTL(JSP Standard Tag Library),即 JSP 标准标签库.标签库是为了替换代码脚本,使得整个 jsp 页面变得更加简洁. JSTL 有五个功能不同的 ...
- HDU6375双端队列
要点分析: 1.本题可以使用C++STL中的deque双端队列来方便解决(底层是一个双向的链表) 2.值得注意的是N的上限为150000,所以直接开这么大的空间会超内存,可以配合map一起使用 关于双 ...
- Openstack Ocata 负载均衡安装(二)
Openstack OCATA 负载节点(二) 安装haproxy: apt install haproxy 配置haproxy: vim /etc/haproxy/haproxy.cfg globa ...
- oracle优化求生指南脚本记录
1.查找未使用索引 /* Formatted on 2020/5/12 下午 03:32:39 (QP5 v5.163.1008.3004) */ WITH IN_PLAN_OBJECTS AS (S ...
- 1.2V转3V芯片,电路图很少就三个元件
1.2V的镍氢电池由于稳定高,应用产品也是很广,但是由于电压低,需要1.2V转3V芯片,来将1.2V的电压升压转3V,稳定输出供电. 一般性的1.2V转3V芯片,都是用PW5100比较多,固定输出电压 ...
- Python设计模式面向对象编程
前言 本篇文章是基于极客时间王争的<设计模式之美>做的总结和自己的理解. 说到面向对象编程,作为一个合格的Pythoner,可以说信手拈来.毕竟在Python里"万物都是对 ...