Codeforces Round #712 (Div. 2) 个人题解
这一场打的又很差(掉分预定),D题想不出来。
A. Déjà Vu
这题首先判断字符串是否全由 a 组成,如果是的话输出 NO
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _;
for (cin >> _; _--;) {
string s;
cin >> s;
int N = s.length();
// find_first_not_of
auto i = s.find_first_not_of('a');
if (i == string::npos) {
cout << "NO\n";
continue;
}
int j = (i < N / 2 ? N - i : N - i - 1);
cout << "YES\n";
cout << s.substr(0, j) << 'a' << s.substr(j) << "\n";
}
return 0;
}
B. Flip the Bits
题意:给你一个 01 初始序列和目标序列,每次可以选择前 \(2\times x\) 个位置异或1(前提是选择区域的0和1个数相等),问你有没有办法变成目标序列。
思路:待补
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _;
for (cin >> _; _--;) {
int n;
string a, b;
cin >> n >> a >> b;
int sa = 0, sb = 0;
bool f = true;
for (int i = 0; i < n; ++i) {
sa += 2 * (a[i] - '0') - 1;
sb += 2 * (b[i] - '0') - 1;
// cout << sa << " " << sb << "\n";
f = f && abs(sa) == abs(sb);
}
// cout << sa << " " << sb << "\n";
f = f && sa == sb;
cout << (f ? "YES\n" : "NO\n");
}
return 0;
}
C. Balance the Bits
题意:给你一个01序列,问你能不能构造两个合法的括号序列a,b,使得当 \(s[i] = 1\) 时,\(a[i] = b[i]\) ,当 \(s[i] = 0\) 时,\(a[i] != b[i]\)
思路:首先,两个字符串序列必须以( 开头,) 结尾,其实,由于 ( 和)的个数和 \(n\) 为偶数所以 \(s\) 序列中 1 的个数也必为偶数。
接下来就是模拟条件了
AC 代码
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int _;
for (cin >> _; _--;) {
int n, t = 0;
string s;
cin >> n >> s;
int cnt = count(s.begin(), s.end(), '1');
if (s[0] != '1' || s[n - 1] != '1' || cnt & 1) {
cout << "NO\n";
continue;
}
cnt /= 2;
string a(n, '*'), b(n, '*');
for (int i = 0; i < n; ++i) {
if (s[i] == '0') {
if (t == 0) a[i] = ')', b[i] = '(';
else
a[i] = '(', b[i] = ')';
t ^= 1;
} else {
if (cnt) {
a[i] = b[i] = '(';
cnt--;
} else
a[i] = b[i] = ')';
}
}
cout << "YES\n";
cout << a << "\n"
<< b << '\n';
}
return 0;
}
Codeforces Round #712 (Div. 2) 个人题解的更多相关文章
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #545 (Div. 1) 简要题解
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #821(Div.2) (A-C) 题解
Codeforces Round #821(Div.2) (A-C) A.Consecutive Sum 大致题意 给定一组共 n 个数据 ,如果俩个数的下标在 mod k 意义下同余,则可以交换a[ ...
随机推荐
- three.js 汽车行驶效果
实现原理是使用TWEEN.Tween实现动画效果 实现 汽车模型加载 使用Promise编写模型的异步加载方法 Car.prototype.loadCar = function (position, ...
- SpringCore完整学习教程3,入门级别
从第三章开始 3. Profiles Spring profile提供了一种方法来隔离应用程序配置的各个部分,并使其仅在某些环境中可用.任何@Component.@Configuration或@Con ...
- Cocos Creator性能调优
一. 为什么要做性能优化 性能:是程序的一种优秀的能力.唤醒快.运行持久.稳定 这种能力正在游戏上能让你的用户感觉很爽,特征表现为加载快.运行流畅.不卡顿. 所以,性能优化的终极目标是,让你的用户体验 ...
- SpringBoot使用maven打jar包配置
在pom.xml文件中加入依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactI ...
- VMware安装虚拟机详细步骤
在VMware中安装CentOS7 01.目录 CentOS7的下载 CentOS7的配置 CentOS7的安装 CentOS7的网络配置 自动获取IP 固定获取IP 02.安装前提 准备工作: 提前 ...
- LCIS最长公共上升子序列!HDU-1423
This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence ...
- 华企盾DSC防泄密系统:半透明问题调试方法
1.先添加下图中的注册表 2.用debugview工具监控操作过程,然后找到后面是DSE_SANDBOX,把它前面的值一个一个加到控制台的半透明沙盒对象里面调,直到找到可以正常的为止 3.用supe ...
- Pikachu漏洞靶场 File Inclusion(文件包含漏洞)
File Inclusion(文件包含漏洞) 本地文件包含 url: 192.168.171.30/pikachu/vul/fileinclude/fi_local.php?filename=file ...
- SQL语句(mysql)「一」
SQL的一些常用语句 创建类 CREAT DATABASE <数据库名>; 该方法创建一个数据库,当要使用一个数据库的时候,使用指令: USE <数据库名>; 查看当前正在使用 ...
- Linux SNMP监控配置
1, 安装SNMP服务 [root@zlm log]# yum -y install net-snmp net-snmp-utils 2, 编辑SNMP配置文件[root@zlm log]# vim ...