http://codeforces.com/contest/923/problem/D

题意:

A-->BC , B-->AC , C-->AB , AAA-->empty

问指定串S是否能变成目标串T

发现1:B与C等价

B-->AC-->AAB-->AAAC-->C

C-->AB-->AAC-->AAAB-->B

发现2:B前面的A可以消去

AB-->AAC-->AAAB-->A

新的变换:

A-->BB , B-->AB , AB-->A , AAA-->empty

所以:

结论1:B之前可以增删任意个A

结论2:在A的位置可以变成任意偶数个B

结合结论1和结论2,现在只剩下末尾的A待解决

末尾的A是无法增加的,所以只能考虑把S串末尾多余的A删去

综上所述,本题解法:

1、若S和T的 b的数量的奇偶性不同,则无解

因为B的改动只能是偶数个

2、若T中b的数量<S中b的数量,则无解

因为b只能加不能减

3、若T末尾A的数量>S末尾A的数量,则无解

因为末尾的A只能减不能加

删去末尾相同数量的A

考虑末尾的A

4、若 决定 变化最后1个A-->BB,在满足排除上面三种无解的前提下,若S中末尾A的数量>T中末尾B的数量 且 S中B的数量<T中B的数量,则有解

5、若决定删去3个A,若S串末尾A的数量是3的倍数 且 不存在 删去末尾相同数量的A后 S串是空串 T串不是空串

#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; const int maxn=; int sa[maxn],sb[maxn],ta[maxn],tb[maxn]; int n,m;
char s[maxn],t[maxn]; int main()
{
scanf("%s%s",s+,t+);
n=strlen(s+);m=strlen(t+);
for(int i=;i<=n;i++)
{
if(s[i]=='A')sa[i]=sa[i-]+;
sb[i]=sb[i-]+(s[i]=='B'||s[i]=='C');
}
for(int i=;i<=m;i++)
{
if(t[i]=='A')ta[i]=ta[i-]+;
tb[i]=tb[i-]+(t[i]=='B'||t[i]=='C');
}
int Q;
scanf("%d",&Q);
int l,r,Sa,Sb,Ta,Tb,lenS,lenT;
while(Q--)
{
scanf("%d%d",&l,&r);
Sa=min(r-l+,sa[r]);
Sb=sb[r]-sb[l-];
lenS=r-l+;
scanf("%d%d",&l,&r);
Ta=min(r-l+,ta[r]);
Tb=tb[r]-tb[l-];
lenT=r-l+;
if(Tb<Sb||((Tb&)!=(Sb&))||Ta>Sa) printf("");
else if((Ta<Sa&&Tb>Sb)||(( Ta!=lenS || Ta==lenT) && (Sa-Ta)%==)) printf("");
else printf("");
}
return ;
}

Codeforces 923 D. Picking Strings的更多相关文章

  1. 【CodeForces】947 D. Picking Strings

    [题目]D. Picking Strings [题意]给定只含'A','B','C'的字符串,支持以下变换:1.A - BC   2.B - AC   3.C - AB   4.AAA - empty ...

  2. Codeforces 385B Bear and Strings

    题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...

  3. Codeforces 482C Game with Strings(dp+概率)

    题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,如今从中选定一个字符串为答案串,你不知道答案串是哪个.可是能够通过询问来确定, 每次询问一个位置 ...

  4. Codeforces Round #470 (rated, Div. 1, based on VK Cup 2018 Round 1) 923D 947D 948E D. Picking Strings

    题: OvO http://codeforces.com/contest/947/problem/D 923D 947D 948E 解: 记要改变的串为 P1 ,记目标串为 P2  由变化规则可得: ...

  5. Codeforces 923 C. Perfect Security

    http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...

  6. Codeforces 923 B. Producing Snow

    http://codeforces.com/contest/923/problem/B 题意: 有n天,每天产生一堆体积为Vi的雪,每天所有雪堆体积减少Ti 当某一堆剩余体积vi<=Ti时,体积 ...

  7. Codeforces 923 A. Primal Sport

    http://codeforces.com/contest/923/problem/A 题意: 初始有一个x0,可以选择任意一个<x0的质数p,之后得到x1为≥x0最小的p的倍数 然后再通过x1 ...

  8. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. CodeForces 682D Alyona and Strings (四维DP)

    Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...

随机推荐

  1. Flutter - 快速创建Stateless和Stateful组件

    1. 快速创建Stateless组件 输入stle,回车 class extends StatelessWidget { @override Widget build(BuildContext con ...

  2. winform 保存文件 打开文件 选择文件 字体样式颜色(流 using System.IO;)

    string filePath = ""; private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) ...

  3. Asp.net中汉字转换成为拼音

    1.应用场景 将汉字转换为拼音(eg:"我爱你"--->"WOAINI") 取各个汉字的首字母(eg:"我是中国人"--->&q ...

  4. SpringBoot整合Mybatis之进门篇

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...

  5. linux下SpringBoot Jar包自启脚本配置

    今天整理服务器上SpringBoot项目发现是自启的,于是想看看实现.翻看离职同事的交接文档发现一个***.service文件内容如下 [Unit] Description=sgfront After ...

  6. 镜像仓库管理:与Portus不得不说的那些事

    背景: 目前在做一个云计算相关的项目,其中有这样一个需求:每个平台用户都有自己的docker镜像仓库(docker registry),用户可以对自己的镜像仓库的push/pull权限进行管理,也就是 ...

  7. 毕业回馈-89c52之最小系统

    今天分享一个51单片机最小系统的电路板设计(原理图+PCB) 技术手册上面对于51单片机最小系统作如下要求: 下载电路主要有以下几种: 采用RS-232转换器下载:(R1OUT-P3.0;T1IN-P ...

  8. js执行问题

    金三银四搞事季,前端这个近年的热门领域,搞事气氛特别强烈,我朋友小伟最近就在疯狂面试,遇到了许多有趣的面试官,有趣的面试题,我来帮这个搞事 boy 转述一下. 以下是我一个朋友的故事,真的不是我. f ...

  9. PHP完美分页类

    <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...

  10. Leetcode——30.与所有单词相关联的字串【##】

    @author: ZZQ @software: PyCharm @file: leetcode30_findSubstring.py @time: 2018/11/20 19:14 题目要求: 给定一 ...