题:

  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. java源码 -- LinkedHashSet

    问题 (1)LinkedHashSet的底层使用什么存储元素? (2)LinkedHashSet与HashSet有什么不同? (3)LinkedHashSet是有序的吗? (4)LinkedHashS ...

  2. Feign【替换默认的feign client】

    说明: feign默认情况下使用的是JDK原始的URLConnection发送的HTTP请求,没有使用到连接池,但是对每个地址会保持长连接,即HTTP的persistence connection.我 ...

  3. C语言细节

    一些常见细节 int *p[]和 int (*p)[] 的区别 int *p[4]; //定义一个指针数组,该数组中每个元素是一个指针,每个指针指向哪里就需要程序中后续再定义了. int (*p)[4 ...

  4. VC++类型转换

    一.其他数据类型转换为字符串 短整型(int) itoa(i,temp,10):///将i转换为字符串放入temp中,最后一个数便是十进制 itoa(i,temp,2):///按二进制方式转换 长整型 ...

  5. GC(Garbage Collection)

    GC(Garbage Collection) GC背景 ​  创建对象会消耗内存,如果不回收对象占用的内存,内存使用率会越来越高,最终出现OutOfMemoryError(OOM) ​  在C++中专 ...

  6. 其实每个行业都有各自的辛苦,好的程序员并不累,他们乐此不疲(见过太多在职位事业、人生方向上随转如流的人,累了疲乏了就去做别的事情了。必须有自己的坚守和立足的点,自我驱动,否则沦为在别人的体制制度中被驱赶一生)good

    作者:陈柯好链接:https://www.zhihu.com/question/39813913/answer/104275537来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  7. 官网下载CentOS教程(各版本)

    1.进入官网,并点击下图所示的红框(alternative downloads) 官网网址:https://www.centos.org/download/  2.在往下翻,可以看到如下图的历史版本, ...

  8. Codeforces 666E Forensic Examination(广义后缀自动机+线段树合并)

    将所有串(包括S)放一块建SAM.对于询问,倍增定位出该子串所在节点,然后要查询的就是该子串在区间内的哪个字符串出现最多.可以线段树合并求出该节点在每个字符串中的出现次数. #include<b ...

  9. IMPDPORA-27046,dump文件损坏

    客户提出导入报错 一.报错如下 SYMPTOMS DataPump Import (IMPDP) fails with the following errors: ORA-: invalid oper ...

  10. LeetCode 1047. Remove All Adjacent Duplicates In String

    1047. Remove All Adjacent Duplicates In String(删除字符串中的所有相邻重复项) 链接:https://leetcode-cn.com/problems/r ...