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[ ...
随机推荐
- BI工具:让数据分析井然有序一望而知
BI(Business Intelligence)工具是一类专门用于数据分析和决策支持的软件工具. 它们能够将企业内部和外部的数据进行整合.处理和可视化,帮助用户从海量数据中获取有价值的见解和洞察,并 ...
- [JDK/APM] 应用诊断工具之VisualVM
1 概述 1.1 简介 VisualVM is a visual tool integrating commandline JDK tools and lightweight profiling ca ...
- 【总结】MySQL使用优化
一.表设计 1.避免使用null 占用额外空间.索引无效.检索麻烦 2.能用int 不用varchaer,能用varchaer 不用text 3.int 最好给默认值 0 .varchar empt ...
- Linux笔记03: Linux常用命令_3.1命令的基本格式
3.1命令的基本格式 3.1.1 命令提示符 [root@localhost ~]# 这就是Linux系统的命令提示符.各部分含义如下: ●[]:这是提示符的分隔符号,没有特殊含义. ●root:显示 ...
- 4 HTTP的“四层”和“七层”
目录 1 四层:TCP/IP 网络分层模型 2 七层:OSI网络分层模型 3 TCP/IP 协议栈的工作方式 1 四层:TCP/IP 网络分层模型 四层是指TCP/IP 网络分层模型. 第一层:&qu ...
- django-filter的详细使用
有时候前端需要各种各样的过滤查询,如果自己写多少有点麻烦和冗余.使用django-filter就可以很好的解决这个问题. django-filter可以用在django上, 也与配合drf一起使用. ...
- 关于SpringBoot中出现的循环依赖问题
环境: SpringBoot2.7.8 背景: 在增加出库订单时需要对物品表的的数量进行修改 因此我在OutboundController中创建了几个公共方法,并将其注入到Spring中,结果给我报了 ...
- apache+mysql+php环境安装及配置
一.安装mysql 1.yum安装mysql # yum -y install mysql mysql-server 2.安装mariadb,用mariadb来启动数据库,systemctl star ...
- 春秋云镜 - CVE-2022-28512
Fantastic Blog (CMS)是一个绝对出色的博客/文章网络内容管理系统.它使您可以轻松地管理您的网站或博客,它为您提供了广泛的功能来定制您的博客以满足您的需求.它具有强大的功能,您无需接触 ...
- Programming abstractions in C阅读笔记:p181-p183
<Programming Abstractions In C>学习第61天,p181-p183总结. 一.技术总结 1.linear search algorithm 2.lexicogr ...