Codeforces 923 D. Picking Strings
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的更多相关文章
- 【CodeForces】947 D. Picking Strings
[题目]D. Picking Strings [题意]给定只含'A','B','C'的字符串,支持以下变换:1.A - BC 2.B - AC 3.C - AB 4.AAA - empty ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces 482C Game with Strings(dp+概率)
题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,如今从中选定一个字符串为答案串,你不知道答案串是哪个.可是能够通过询问来确定, 每次询问一个位置 ...
- 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 由变化规则可得: ...
- Codeforces 923 C. Perfect Security
http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...
- Codeforces 923 B. Producing Snow
http://codeforces.com/contest/923/problem/B 题意: 有n天,每天产生一堆体积为Vi的雪,每天所有雪堆体积减少Ti 当某一堆剩余体积vi<=Ti时,体积 ...
- Codeforces 923 A. Primal Sport
http://codeforces.com/contest/923/problem/A 题意: 初始有一个x0,可以选择任意一个<x0的质数p,之后得到x1为≥x0最小的p的倍数 然后再通过x1 ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 682D Alyona and Strings (四维DP)
Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...
随机推荐
- 《Effective Java》 学习笔记 —— 并发
<Effective Java>第二版学习笔记之并发编程. 第66条 同步访问共享的可变数据 * 关键字synchronized可以保证在同一时刻只有一个线程可以执行某个方法或代码块. * ...
- Azure SQL Database Active Geo-Replication 简介
对于数据库的维护来说,备份工作可谓是重中之重.MS Azure 当然也提供了很完善的数据库备份功能.但是在动手创建备份计划前请思考一下备份工作的真实目的.当然首先要保证数据的安全,一般来说定时创建数据 ...
- Windows Server 2003出现Directory Listing Denied This Virtual Directory does not allow contents to be listed.的解决方案
Directory Listing DeniedThis Virtual Directory does not allow contents to be listed. 是目录权限无法访问的问题 解决 ...
- kettle开源项目部署文档
kettle开源项目部署文档 1.kettle简介 kettle是一款国外开源的ETL(Extract Transform Load)工具,纯java编写,可以在Windows.Linux.Unix上 ...
- 第十五次ScrumMeeting博客
第十五次ScrumMeeting博客 本次会议于12月4日(一)22时整在3公寓725房间召开,持续30分钟. 与会人员:刘畅.辛德泰.张安澜.赵奕.方科栋. 1. 每个人的工作(有Issue的内容和 ...
- LazyBug环境部署
前言: LazyBug(授权协议:GPL)是一款PHP编写的开源HTTP接口测试管理系统,它集成了接口的测试.管理.维护.自动化回归等一系列工作,以实现对测试效率和管理效率的提高. 本次教程仅支持Wi ...
- CodeMirror 小册子
User manual and reference guide version 5.41.1 用户手册和参考指南 CodeMirror is a code-editor component ...
- Alpha冲刺——day7
Alpha冲刺--day7 作业链接 Alpha冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602634 ...
- #Leetcode# 917. Reverse Only Letters
https://leetcode.com/problems/reverse-only-letters/ Given a string S, return the "reversed" ...
- Linux命令(七)查找文件或目录 find
find 命令可以根据给定的路劲和表达式查找指定的文件或目录.find 参数选项很多,并且支持正则表达式,功能强大. 和管道结合使用可以实现复杂的功能,是系统管理和普通用户必须掌握的命令. 一.fin ...