CF1494A ABC String 题解
Content
给定 \(T\) 个仅包含大写字母 A,B,C 的字符串 \(s\)。问你是否能够通过将每个 A,B,C 换成 (,) 中的一个(同一个字母必须要换成同一个字符),使得最后得到的括号序列能够完全匹配。
数据范围:\(1\leqslant t\leqslant 10^3\),\(2\leqslant |s|\leqslant 50\)。
Solution
不愧是 bruteforces,开头第一题就来暴力。
我的想法是直接枚举每个字母换成左括号还是右括号。排除全是左括号和全是右括号的情况以后,得到的就只有 \(6\) 种情况:
| A | B | C | |
|---|---|---|---|
| 1 | ( | ( | ) |
| 2 | ( | ) | ( |
| 3 | ( | ) | ) |
| 4 | ) | ( | ( |
| 5 | ) | ( | ) |
| 6 | ) | ) | ( |
拿这六种情况一一代入原字符串里面中,只要有一种情况能够将原字符串变换之后的括号序列能够完全匹配就是 YES,如果六种情况全部都不能匹配就是 NO。
感觉没人比我更暴力了(
Code
std :: map<char, int> vis;
inline bool check(std :: string s) {
std :: stack<char> q; int lens = s.size();
F(i, 0, lens - 1) {
if(s[i] == '(') q.push(s[i]);
else {
if(q.empty()) return 0;
q.pop();
if(q.empty() && s[i + 1] == ')') return 0;
}
}
return q.empty();
}
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
MT {
vis.clear();
crstr(s, len);
std :: string tmp = s;
F(i, 0, len - 1) {
if(s[i] == 'A' || s[i] == 'B') s[i] = '(';
else s[i] = ')';
}
if(check(s)) {puts("Yes"); continue;}
s = tmp;
F(i, 0, len - 1) {
if(s[i] == 'A' || s[i] == 'C') s[i] = '(';
else s[i] = ')';
}
if(check(s)) {puts("Yes"); continue;}
s = tmp;
F(i, 0, len - 1) {
if(s[i] == 'A') s[i] = '(';
else s[i] = ')';
}
if(check(s)) {puts("Yes"); continue;}
s = tmp;
F(i, 0, len - 1) {
if(s[i] == 'A') s[i] = ')';
else s[i] = '(';
}
if(check(s)) {puts("Yes"); continue;}
s = tmp;
F(i, 0, len - 1) {
if(s[i] == 'A' || s[i] == 'C') s[i] = ')';
else s[i] = '(';
}
if(check(s)) {puts("Yes"); continue;}
s = tmp;
F(i, 0, len - 1) {
if(s[i] == 'A' || s[i] == 'B') s[i] = ')';
else s[i] = '(';
}
if(check(s)) puts("Yes");
else puts("No");
}
return 0;
}
CF1494A ABC String 题解的更多相关文章
- AtCoder ABC 242 题解
AtCoder ABC 242 题解 A T-shirt 排名前 \(A\) 可得 T-shirt 排名 \([A+1,B]\) 中随机选 \(C\) 个得 T-shirt 给出排名 \(X\) ,求 ...
- [LeetCode] Decode String 题解
题目 题目 s = "3[a]2[bc]", return "aaabcbc". s = "3[a2[c]]", return " ...
- 多校第十场1009 CRB and String题解
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给你两个字符串s和t,你能够在字符串s中随意选一个字符c,在该字符c后插入一个字符d(d! ...
- csp-s模拟测试b组加餐antipalindome,randomwalking,string题解
题面:https://www.cnblogs.com/Juve/articles/11599318.html antipalindome: 打表找规律? 对于一个回文串,我们只要保证3位以内不回文即可 ...
- HDU3336 Count the string 题解 KMP算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 题目大意:找出字符串s中和s的前缀相同的所有子串的个数. 题目分析:KMP模板题.这道题考虑 n ...
- CF23A You're Given a String... 题解
Content 给定一个长度为 \(n\) 的字符串,求出至少出现两次的最长子串的长度. 数据范围:\(1\leqslant n\leqslant 100\). Solution 我们直接暴力求出每个 ...
- @atcoder - AGC036E@ ABC String
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个仅由 A, B, C 组成的字符串 S. 求 S 的一个 ...
- Codeforces #698 (Div. 2) E. Nezzar and Binary String 题解
中文题意: 给你两个长度为 \(n\) 的01串 \(s,f,\)有 \(q\) 次询问. 每次询问有区间 \([\ l,r\ ]\) ,如果 \([\ l,r\ ]\) 同时包含\(0\)和\(1\ ...
- CF1440A Buy the String 题解
Content 有 \(t\) 组询问,每组询问给出一个长度为 \(n\) 的 \(0/1\) 串,你可以花 \(h\) 的代价把 \(0\) 修改成 \(1\) 或者把 \(1\) 修改成 \(0\ ...
随机推荐
- Vue3学习与实战 · 全局挂载使用Axios
在vue2中会习惯性的把axios挂载到全局,以方便在各个组件或页面中使用this.$http请求接口.但是在vue3中取消了Vue.prototype,在全局挂载方法和属性时,需要使用官方提供的gl ...
- 基于 Docker 安装 RocketMQ
docker-compose.yml version: '3.5' services: rmqnamesrv: image: foxiswho/rocketmq:server container_na ...
- Java设计模式之(十二)——观察者模式
1.什么是观察者模式? Define a one-to-many dependency between objects so that when one object changes state, a ...
- 网络管理之命令行工具nmcli
参考Ubuntu官方文档和Red Hat,本文采用Google翻译. NETWORKMANAGER 简介 介绍 NetworkManager 提供的默认联网服务是一个动态网络控制和配置守护进程,它尝试 ...
- python3安装,支持openssl,支持采集https
python3安装,支持openssl,支持采集https 坑好多,特别是安装的时候,各种不匹配,服务器默认配置是python2,升级3后,采集的时候用到openssl,花了两天也没搞定各种错误,也许 ...
- R语言hist重叠图作法
set.seed(1) h1<-hist(rnorm(1000,100,5)) h2<-hist(rnorm(1000,99,5)) plot(h2,col=rgb(255,0,0,50, ...
- 压力测试工具——apchebench(简称ab)
ab的原理 ab的原理:ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问.它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也可以测试nginx.li ...
- Excel—分组然后取每组中对应时间列值最大的或者最小的
1.MAX(IF(A:A=D2,B:B)) 输入函数公式后,按Ctrl+Shift+Enter键使函数公式成为数组函数公式. Ctrl+Shift+Enter: 按住Ctrl键不放,继续按Shift键 ...
- Excel-转换单元格格式的函数或“方法”汇总
14.转换单元格格式的函数或"方法"汇总 =value(单元格) #转换为数值 =A1&"" #转换A1为文本 = ...
- abide, able, abnormal
abide 近/反义词:1. 忍受: bear, endure, put up with, stand, tolerate2. 遵守(abide by): accept, comply, confor ...