Educational Codeforces Round 130 (Rated for Div. 2) C. awoo's Favorite Problem
https://codeforc.es/contest/1697/problem/C
因为规则中,两种字符串变换都与‘b’有关,所以我们根据b的位置来进行考虑;
先去掉所有的'b',如果两字符串不相等就“NO”;
否则通过‘b'在a,b串中的位置,如果posa>posb,那么他们之间如果出现'a'就说明不可能
如果posb<posa,那么他们之间如果出现'c'说明不可能
1 # include<iostream>
2 # include<bits/stdc++.h>
3 using namespace std;
4 const int N = 3e5 + 10;
5 #define int long long
6 # define endl "\n"
7 int suma[N], sumc[N];
8 char a[N], b[N];
9 char newa[N], newb[N];
10 int posa[N], posb[N];
11 void solve() {
12 int n;
13 cin >> n;
14 cin >> a + 1 >> b + 1;
15 int cnt1 = 0, cnt2 = 0;
16 for (int i = 1; i <= n; ++i) {
17 if (a[i] == 'a') suma[i] = suma[i - 1] + 1;
18 else suma[i] = suma[i - 1];
19 if (a[i] == 'c') sumc[i] = sumc[i - 1] + 1;
20 else sumc[i] = sumc[i - 1];
21 if (a[i] != 'b') newa[++cnt1] = a[i];
22 if (b[i] != 'b') newb[++cnt2] = b[i];
23 }
24
25 if (cnt1 != cnt2) {
26 cout << "NO" << endl;
27 return;
28 }
29 for (int i = 1; i <= cnt1; ++i) {
30 if (newa[i] != newb[i]) {
31 cout << "NO" << endl;
32 return;
33 }
34 }
35 cnt1 = 0, cnt2 = 0;
36 for (int i = 1; i <= n; ++i) {
37 if (a[i] == 'b') posa[++cnt1] = i;
38 if (b[i] == 'b') posb[++cnt2] = i;
39 }
40 if (cnt1 != cnt2) {
41 cout << "NO" << endl;
42 return;
43 }
44 for (int i = 1; i <= cnt1; ++i) {
45 int x = posa[i], y = posb[i];
46 if (x < y) {
47 if (suma[y] - suma[x - 1] != 0) /*前缀和判断a的位置*/
{
48 cout << "NO" << endl;
49 return;
50 }
51 }
52 if (x > y) {
53 if (sumc[x] - sumc[y - 1] != 0) {
54 cout << "NO" << endl;
55 return;
56 }
57 }
58
59 }
60 cout << "YES" << endl;
61 }
62 int tt;
63 signed main() {
64 ios::sync_with_stdio(false);
65 cin.tie(0);
66 cout.tie(0);
67
68 cin >> tt;
69
70 while (tt--)solve();
71 return 0;
72 }
73 /*
74
75 */
主要是通过前缀和来判断两个pos之间是否存在'a'或者'c'的操作
Educational Codeforces Round 130 (Rated for Div. 2) C. awoo's Favorite Problem的更多相关文章
- Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem
题意:给串s,每次询问k个数a,l个数b,问a和b作为后缀的lcp的综合 题解:和bzoj3879类似,反向sam日神仙...lcp就是fail树上的lca.把点抠出来建虚树,然后在上面dp即可.(感 ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp
D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \( ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 【数学+分块】
一.题目 D. Yet Another Subarray Problem 二.分析 公式的推导时参考的洛谷聚聚们的推导 重点是公式的推导,推导出公式后,分块是很容易想的.但是很容易写炸. 1 有些地方 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
随机推荐
- 这三大特性,让 G1 取代了 CMS!
大家好,我是树哥. 之前我们聊过 CMS 回收器,但那时候我们说 CMS 回收器已经落伍了,现在应该是用 G1 回收器的时候了.那么 G1 回收器到底有什么魔力,它比 CMS 回收器相比强在哪里呢?今 ...
- ansible 002 连接被控端 inventory ansible.cfg ansible-adhoc ansible原理
ssh用普通用户连接被控端 配置主机清单 (/etc/hosts域名解析为前提) [root@workstation ansible]# cat hosts servera serverb [root ...
- 第十五章 部署zookeeper集群
1.集群规划 主机名 角色 IP hdss7-11.host.com k8s代理节点1.zk1 10.4.7.11 hdss7-12.host.com k8s代理节点2.zk2 10.4.7.12 h ...
- KingbaseFlySync ddl变更流程
关键字: KingbaseFlySync.Linux.x86_64.mips64el.aarch64.Java 一.ddl变更流程 1. 停掉客户业务,保证没有新数据产生 确认Oracle数据库上所有 ...
- 配置联想IMM使用AD账户登录
IMM是联想(IBM)服务器的管理卡Integrated Management Module的缩写,现在是第二个版本.通过它可以远程管理服务器,就像你在服务器面前操作一样.可以修改BIOS设置,可以重 ...
- Elasticsearch: 使用URI Search
在Elasticsearch中,我们可以使用_search终端进行搜索.这个在我之前的文章 "开始使用Elasticsearch (2)" 中有很多的描述.针对这种搜索,我们可以使 ...
- 不停机为虚拟机添加主机磁盘(以VMware Workstation为例)
VMware Workstation软件上安装的centos7系统,新增磁盘后使用fdisk -l命令查看不到新增的磁盘,有没有办法在不重启的情况下添加上新磁盘? 有办法 具体如下: # 查看主机总线 ...
- 洛谷P1714 切蛋糕(单调队列)
先放代码...... 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=5e5+10,M=0x3f3f3f3f; ...
- C#中Math.Round()实现中国式四舍五入问题
C#中的Math.Round()并不是使用的"四舍五入"法.实际上是四舍六入五取偶. 对于这个问题我们常见的解决方式是使用MidpointRounding.AwayFromZero ...
- 微信小程序中视频的显示与隐藏
在微信小程序中实现视频的播放与暂停 需求: 视频列表中只能有一个视频在播放 点击视频实现播放与暂停功能 加载完成显示图片,点击后变为视频播放 从上次播放的位置进行播放 思路: 定义一个标记变量,控制视 ...