题:

  OvO http://codeforces.com/contest/947/problem/D

  923D 947D 948E

解:

  记要改变的串为 P1 ,记目标串为 P2 

  由变化规则可得:

  1. B -> AC -> AAB -> AAAC -> C ( 即 B -> C -> B )

  2. AB -> AAC -> AAAB -> B (即 AB -> B )

  3. B -> AC -> AB ( 即 B -> AB )

  4. A -> BC -> BB ( 即 A -> BB )

  (由规则1可得,B 与 C 等价,所以下文 C 全由 B代替)

  那么对于一个串 S ,可以从这个串中提取 3 个特征,记这3个特征为 val0, val1, val2,

  这3个特征的意义为:

    对于串 S,把 S 串分成2个部分 S1, S2,其中 S2 是 S 的后缀,其内含字符全为 A,使 S2 长度尽可能长,记 S2 串长度为 val2 。S1 串为去掉 S2 后的部分,记 S1 串中非 A 字符的个数为 val1 。并且,如果 S1 串为空,记 val0=0,否则 val=1。

  (接下去的思路就是转化 P1 中的 S1 与 S2,使其与 P2 中的 S1,S2 相同)

  然后进行分类讨论,以下 5 种情况,P1 串无法转换为 P2 串(不具体证明)

  1. (P1.val1 & 1) != (P2.val1 & 1)

  2. P1.val1 > P2.val1

  3. P1.val2 < P2.val2

  4. P1.val1 == P2.val1 && (P1.val2 - P2.val2) % 3 != 0

  5. P1.val0 == 0 && P1.val1 < P2.val1 && P1.val2 == P2.val2

  其余情况,P1 均可以转化为 P2

  

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio> using namespace std; struct Val
{
int val0,val1,val2;
} ; const int M=1e5+44; char s[2][M];
int len[2],p[2][M],a[2][M],lst[2][M],b[2][M];
int lans,ans[M]; void init(int id)
{
int tmp;
scanf("%s",s[id]+1);
len[id]=strlen(s[id]+1);
for(int i=1;i<=len[id];i++)
if(s[id][i]=='A') p[id][i]=0;
else p[id][i]=1;
a[id][0]=b[id][0];
for(int i=1;i<=len[id];i++)
a[id][i]=a[id][i-1]+(p[id][i]==0),b[id][i]=b[id][i-1]+(p[id][i]==1);
tmp=0;
for(int i=1;i<=len[id];i++)
if(p[id][i]==1)
tmp=i,lst[id][i]=tmp;
else lst[id][i]=tmp;
} Val solve(int id,int li,int ri)
{
int tag=lst[id][ri],part0,part1,part2;
if(tag<li) tag=li-1,part0=0;
else part0=1;
part2=(a[id][ri]-a[id][tag]);
part1=(b[id][ri]-b[id][li-1]);
return Val{part0,part1,part2};
} bool check(Val tp0,Val tp1)
{
if((tp0.val1&1)!=(tp1.val1&1)) return false;
if(tp0.val1>tp1.val1) return false;
if(tp0.val2<tp1.val2) return false;
if(tp0.val1==tp1.val1 && (tp0.val2-tp1.val2)%3!=0) return false;
if(tp0.val0==0 && tp0.val1<tp1.val1 && tp0.val2==tp1.val2) return false;
return true;
} int main()
{
init(0),init(1);
int cas,li0,ri0,li1,ri1;
Val tp[2];
lans=0;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d%d%d",&li0,&ri0,&li1,&ri1);
tp[0]=solve(0,li0,ri0),tp[1]=solve(1,li1,ri1);
// cout<<tp[0]<<" "<<tp[1]<<endl;
if(check(tp[0],tp[1])) ans[++lans]=1;
else ans[++lans]=0;
}
for(int i=1;i<=lans;i++)
printf("%d",ans[i]);
return 0;
}

  

Codeforces Round #470 (rated, Div. 1, based on VK Cup 2018 Round 1) 923D 947D 948E D. Picking Strings的更多相关文章

  1. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)A. Protect Sheep

    http://codeforces.com/contest/948/problem/A   A. Protect Sheep Bob is a farmer. He has a large pastu ...

  2. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow

    题目链接  题意  每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...

  3. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)

    A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)B. Primal Sport

    Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try ...

  5. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) F 构造

    http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义: ...

  6. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) E 贪心

    http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问, ...

  7. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心

    http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x ...

  8. 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

    题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...

  9. 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio

    题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...

随机推荐

  1. Redis部分

  2. CentOS7.0 yum安装 docker

    一.安装docker 1.Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker . root 用户登录操作! 通过  ...

  3. ora00972标识符过长

    oracle10G对于表名的长度限制是30个字节 表名超过30结果不能创建,提示ora00972-标识符过长. 需要将表名控制在30个字节以内

  4. 【坑】关于使用 maven 创建 web 项目以后,el 表达式不被识别的解决方法

    问题描述: 在学习 Ajax 的时候,使用资源路径,博主本着不要硬编码,局使用 el 表达式进行读取项目名,然后发现 el 表达式没有被识别,而是当做字符串 ${pageContext.request ...

  5. (六)lucene之其他查询方式(组合查询,制定数字范围、指定字符串开头)

    本章使用的是lucene5.3.0 指定数字范围查询 package com.shyroke.test; import java.io.IOException; import java.nio.fil ...

  6. 洛谷 P1540 机器翻译

    链接:https://www.luogu.org/problemnew/show/p1540 题目: 题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译 ...

  7. Asp.Net Core 轻松学系列-5利用 Swagger 自动生成接口文档

    目录 前言 结语 源码下载 前言     目前市场上主流的开发模式,几乎清一色的前后端分离方式,作为服务端开发人员,我们有义务提供给各个客户端良好的开发文档,以方便对接,减少沟通时间,提高开发效率:对 ...

  8. MFC如何显示位图

    1. 资源文件中加载 bmp 2.1. 静态加载图片 在属性下设置为如下即可 2.2 动态加载图片 其中要在控件中添加CStatic变量,并且属性设置为如下 并且在按钮控件中加入 如下代码 void ...

  9. 如何解决js地址栏中传递中文乱码的问题

    目标要求: 实现从A页面跳转至B页面,B页面接收A页面通过地址栏传递过来的中文参数,中文不能出现乱码. A页面部分代码(传递参数): var title = "这是中文"; var ...

  10. SpringBoot mysql出现The server time zone value '�й���׼ʱ��' is unrecogni

    MySql :8.0.18 引入的mysql驱动: SpringBoot整合Mybatis的框架,在访问Controller的时候 : ava.sql.SQLException: The server ...