UPC-TrBBnsformBBtion

42 篇文章 1 订阅
30 篇文章 8 订阅

学习犹如逆水行舟,不进则退

UPC-TrBBnsformBBtion

题目描述

Let us consider the following operations on a string consisting of A and B:
Select a character in a string. If it is A, replace it with BB. If it is B, replace with AA.
Select a substring that is equal to either AAA or BBB, and delete it from the string.
For example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA. If the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries ai,bi,ci,di. For each query, determine whether SaiSai+1…Sbi, a substring of S, can be made into TciTci+1…Tdi, a substring of T.
Constraints
1≤|S|,|T|≤105
S and T consist of letters A and B.
1≤q≤105
1≤ai≤bi≤|S|
1≤ci≤di≤|T|

翻译

让我们考虑由A和B组成的字符串执行以下操作:选择字符串中的字符,如果是A可以用BB替代,如果是B可以用AA替代。也可以选择一个AAA或BBB字符串删除。例如,如果对ABA执行第一个操作并选择了第一个字符,则字符串将会变成BBBA。如果对BBBAAAA执行第二个操作,并选择第四到第六个字符,则字符串将变为BBBA。
这些操作可执行任意次数。
给出了两个字符串S和T,以及查询次数q
每次查询都会给出ai,bi,ci,di。对于每个查询,判断由S选取的子串是否可以转换为由T形成的子串。
限制条件
1≤|S|,
.

|T|≤105
S和T由字母A和B组成。
1≤q≤105
1≤ai≤bi≤|S|
1≤ci≤di≤|T|

输入

Input is given from Standard Input in the following format:
S
T
q
a1 b1 c1 d1

aq bq cq dq

翻译

标准输入的输入格式如下:
S
T
q
a1 b1 c1 d1

aq bq cq dq

输出

Print q lines. The i-th line should contain the response to the i-th query. If SaiSai+1…Sbi can be made into TciTci+1…Tdi, print YES. Otherwise, print NO.

翻译

打印q行。第i行应包含对第i个查询结果。如果可以完成转换,则打印YES。否则,打印NO。

Sample Input

BBBAAAABA
BBBBA
4
7 9 2 5
7 9 1 4
1 7 2 5
1 7 2 4

Sample Output

YES
NO
YES
NO

Hint

第一个查询询问字符串ABA是否可以生成BBBA。正如在问题陈述中所解释的,它可以通过第一个操作来完成。
第二个查询询问ABA是否可以生成BBBB,第四个查询询问bbbaaa是否可以生成BBB。两者都不可能。
第三个查询询问字符串BBBAAAA是否可以生成BBBA。正如问题陈述中所解释的,可以通过第二个操作来完成。

解析
通过尝试转换,会发现,无论如何转换都不会使原有的A多一个或者少一个
也就是说如果全部都化简到最简,一定不会出现多一个或者少一个A或者B的情况
也就是说,如果内容相同,位置不同则输出YES,如果内容不相同则输出NO。

AC时间到
附上代码

#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<math.h>
#include<stdio.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const int MAXN=10010;
const ll long_inf=9223372036854775807;
const int int_inf=2147483647;
inline ll read() {
	ll c=getchar(),Nig=1,x=0;
	while(!isdigit(c)&&c!='-')c=getchar();
	if(c=='-')Nig=-1,c=getchar();
	while(isdigit(c))x=((x<<1)+(x<<3))+(c^'0'),c=getchar();
	return Nig*x;
}
char s[500005];
char t[500005];
int ans1[500005];
int ans2[500005];
int main() {
	int ans=0;
	scanf("%s%s",s+1,t+1);
	for(int i=1; s[i]; i++) {
		if(s[i]=='B')
			ans1[i]=ans1[i-1]+2;
		else
			ans1[i]=ans1[i-1]+1;
	}
	for(int i=1; t[i]; i++) {
		if(t[i]=='B')
			ans2[i]=ans2[i-1]+2;
		else
			ans2[i]=ans2[i-1]+1;
	}
	int T=read();
	int a,b,c,d;
	for(int i=0; i<T; i++) {
		a=read(),b=read(),c=read(),d=read();
		int TEMP1=ans1[b]-ans1[a-1];
		int TEMP2=ans2[d]-ans2[c-1];
		if((TEMP1%3)==(TEMP2%3))
			puts("YES");
		else
			puts("NO");
	}
}

思路
记录以下每一段有多少,然后取余3因为只会出现1个和2个,所以这是化简,然后判断是否相同,即所含内容是否相同,如果是则输出YES,否则输出NO。
PS这里的化简有可能将A转换成B,或者B换成A。所以说直接统一先化简成A然后全部删除只剩不能再删除,一个B顶两个A。所以说遇到B加2遇到1加一。最后算够不够。
如果说是
AAA和ABBBAA这种情况
先变成
AAA 和AAAAAAAAA
然后进行删除,
A,A会变成这样。所以要对3取余。因为这个是三个一循环。A还是A AA是AA AAA是‘ ’所以要取余3.

By-轮月

书山有路勤为径,学海无涯苦作舟。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Round moon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值