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的更多相关文章

  1. 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即可.(感 ...

  2. 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 \( ...

  3. Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 【数学+分块】

    一.题目 D. Yet Another Subarray Problem 二.分析 公式的推导时参考的洛谷聚聚们的推导 重点是公式的推导,推导出公式后,分块是很容易想的.但是很容易写炸. 1 有些地方 ...

  4. 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 ...

  5. 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 ...

  6. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  7. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Miller Rabbin 算法—费马定理+二次探测+随机数 (讲解+例题:FZU1649 Prime number or not)

    0.引入 那年,机房里来了个新教练, 口胡鼻祖lhy 第一节课,带我们体验了暴力的神奇, 第二节课,带我们体验了随机数的玄妙, -- 那节课,便是我第一次接触到Miller Rabbin算法, 直到现 ...

  2. C++ 对于函数名的操作,函数名本身和取*以及取&的区别

    void TestFunc() { } int _tmain(int argc, _TCHAR* argv[]) { cout<<TestFunc<<endl; cout< ...

  3. 简单的java代码审计

    描述 很简单的代码审计 java安全--Fastjson反序列化 java安全--SQL注入 Fastjson 反序列化 首先看一下配置文件,对于Maven项目,我们首先从pom.xml文件开始审计引 ...

  4. c++基础思维导图2

    c++基础思维导图2 结构体 结构体的基本概念:用户自定义的数据类型 结构体定义和使用 struct 结构体名{结构体成员} struct 结构体名 变量名: struct 结构体名 变量名 = {成 ...

  5. django_day08_项目相关

    django_day08_项目相关 定义数据库表 from django.db import models # Create your models here. class User(models.M ...

  6. Linux网桥配置(用于大数据虚拟化)

    理解 VMware里面有三个虚拟机,分别为RHEL8,RHEL7,Windows的虚拟机,只有一个物理网卡连接物理网络,现在三台虚拟机都需要直连到物理网络,此时无法访问物理网络,只能给一个虚拟机访问物 ...

  7. KingbaseES V8R3集群运维案例之---主库系统down failover切换过程分析

    ​ 案例说明: KingbaseES V8R3集群failover时两个cluster都会触发,但只有一个cluster会调用脚本去执行真正的切换流程,另一个有对应的打印,但不会调用脚本,只是走相关的 ...

  8. 华南理工大学 Python第5章课后小测-1

    1.(单选)以下哪个函数的定义是错误的?(本题分数:2)A) def vfunc(a,b=2):B) def vfunc(a,b):C) def vfunc(a,*b):D) def vfunc(*a ...

  9. C++ 二级指针与 const 关键字

    可用七种不同的方式将 const 关键字用于二级指针,如下所示: //方式一:所指一级指针指向的数据为常量,以下几种为等效表示 const int ** pptc; //方式一 int const * ...

  10. Docker容器优雅重启

    默认情况下,当 Docker 守护进程终止时,它将关闭正在运行的容器.您可以配置守护程序,以便容器在守护程序不可用时保持运行.此功能称为live-restore.live-restore选项有助于减少 ...