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
由变化规则可得:
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的更多相关文章
- 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 ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow
题目链接 题意 每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...
- 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 ...
- 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 ...
- 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条路目前开启(即能走),剩下的都是关闭状态 定义: ...
- 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), 问, ...
- 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 ...
- 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...
- 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio
题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...
随机推荐
- 自定义 Win10 系统鼠标右键发送到的选项
系统默认的右键「发送到」菜单只有几个特定的项目,如果要想发送到其他目标,可通过在资源管理器地址栏中访问 C:\Users\用户名\AppData\Roaming\Microsoft\Windows\S ...
- GB2312、GBK、GB18030 这几种字符集的主要区别
1 GB2312-80 GB 2312 或 GB 2312-80 是中国国家标准简体中文字符集,全称<信息交换用汉字编码字符集·基本集>,又称 GB 0,由中国国家标准总局发布,1981 ...
- SAS学习笔记3 输入输出格式(format、informat函数)
format函数:定义输出格式 informat函数:定义输入格式 proc format:定义输出格式 从外部读取文件 proc format过程步
- Solr综合案例深入练习
1. 综合案例 1.1. 需求 使用Solr实现电商网站中商品信息搜索功能,可以根据关键字.分类.价格搜索商品信息,也可以根据价格进行排序,并且实现分页功能. 界面如下: 1.2. 分析 开发人员需要 ...
- k8s基础环境搭建
环境准备 服务器之间时间同步 1. 关闭防火墙 systemctl stop firewalld setenforce 0 2. 设置yum源 三台机器都要设置一个master两个node节点 下 ...
- 嗯。。 差不多是第一道自己搞出的状态方程 hdu4502 有一点点变形的背包
吉哥系列故事——临时工计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 1285 拓扑
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- (六)发送、接收SOAP消息(1)
一.为什么要用soap 原本我们使用web服务都是根据wsdl生成客户端(生成一堆java文件)然后再调用,本章节讲解如何用soap消息来替代这种方式. 二.SOAP消息格式 SOAP(简单对象访问协 ...
- JDBC 学习复习9 配置Tomcat数据源
在实际开发中,我们有时候还会使用服务器提供给我们的数据库连接池,比如我们希望Tomcat服务器在启动的时候可以帮我们创建一个数据库连接池,那么我们在应用程序中就不需要手动去创建数据库连接池,直接使用T ...
- Android中BroadcastReceiver的使用
1.Android中广播分为静态注册和动态注册 2.下面是一个简单静态注册的例子 创建一个继承BroadcastReceiver的子类 public class DeviceBootReceiver ...