Codeforces947D. Picking Strings
$n \leq 100000,m \leq 100000$,给长度$n$的字符串$s$和$m$的字符串$t$,只含ABC。定义串$a$可以经过任意次如下操作变成其他串。
现在$q \leq 100000$个询问每次给俩串各指定一个子串,问串$s$的子串能否变成串$t$的子串。
这个题叫细节题,送tourist下榜的。。极其恐怖。更恐怖的是他看起来是模拟题,而且pretest极弱,鬼都不知道自己错哪,先给场上AC的各位大佬献个膝盖。
好开始。首先有重要性质:$B->AC->AAB->AAAC->C$,$C->AB->AAC->AAAB->B$,所以$B=C$,且$AB->B$,因此把$C$看成$B$。而又$B->AC$,$A->BC$,得$B->AB$,$A->BB$,因此$B$前的$A$可以自由增减,且$A$可炸成$BB$。因此把目光投到后缀中的$A$。
首先如果目标串$B$比原始串少,由于$B$无法凭空消失,因此死。
如果$t$中有后缀$A$,$s$是无法凭空制造后缀$A$的,因此必须保留至少同样的数量,否则死。
如果有多出来的$A$,可以炸成$B$,也可三个三个消掉。那就看情况,如果目标串中的$B$和原始串一样,那就不得不三个三个消掉;如果目标串$B$比原始串多,那原始串要么得至少有个$B$,要么得炸一个$A$,您可能想说,不是肯定至少有个$A$或$B$吗不然串就空了那问个毛线,告诉您,这里的$A$是指抵消掉后缀后的!!
//#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<time.h>
//#include<complex>
#include<algorithm>
#include<stdlib.h>
using namespace std; int n,m,q;
#define maxn 200011
char s[maxn],t[maxn];
int ms[maxn],mt[maxn],sums[maxn],sumt[maxn];
int main()
{
scanf("%s%s",s+,t+);
n=strlen(s+); m=strlen(t+);
for (int i=;i<=n;i++) sums[i]=sums[i-]+(s[i]!='A'),ms[i]=s[i]=='A'?ms[i-]+:;
for (int i=;i<=m;i++) sumt[i]=sumt[i-]+(t[i]!='A'),mt[i]=t[i]=='A'?mt[i-]+:;
scanf("%d",&q);
while (q--)
{
int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int ss=sums[y1]-sums[x1-],tt=sumt[y2]-sumt[x2-];
if (((ss&)^(tt&)) || ss>tt) {putchar(''); continue;}
int aa=min(ms[y1],y1-x1+)-min(mt[y2],y2-x2+);
if (aa<) {putchar(''); continue;}
if (tt==ss)
{
if (aa%) putchar('');
else putchar('');
}
else
{
if (aa || ss) putchar('');
else putchar('');
}
}
return ;
}
Codeforces947D. 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 923 D. Picking Strings
http://codeforces.com/contest/923/problem/D 题意: A-->BC , B-->AC , C-->AB , AAA-->empty 问 ...
- 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】【比赛题解】#948 CF Round #470 (Div.2)
[A]Protect Sheep 题意: 一个\(R*C\)的牧场中有一些羊和一些狼,如果狼在羊旁边就会把羊吃掉. 可以在空地上放狗,狼不能通过有狗的地方,狼的行走是四联通的. 问是否能够保护所有的羊 ...
- VK Cup 2018 - Round 1+Codeforces Round #470
A. Primal Sport 题意:有两个人轮流玩游戏.给出数X(i-1),轮到的人需要找到一个小于X(i-1)的素数x,然后得到Xi,Xi是x的倍数中大于等于X(i-1)的最小的数.现在已知X2, ...
- Codeforces Round #470 Div. 2题解
A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Hacker Rank: Two Strings - thinking in C# 15+ ways
March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...
- StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?
StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...
- Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
随机推荐
- js的本质、全局属性
一.js的本质 1.js的本质就是处理数据, 数据来自于后台数据库, 所以变量就起到一个临时数据的作用 Ecmascript 制定了js的数据类型 2.数据类型有哪些? 字符串(string).数字( ...
- 微信小程序 图片加载失败处理方案
小程序端展示网络资源图片可能会失败,下面介绍一种自己的处理方法 1. js文件中判断图片 url 是否存在,存在则正常显示,不存在则替换url为本地默认图片 2. 当图片 url 存在,但是加载失败时 ...
- CSS3常用属性浏览器兼容前缀
1.检测网站https://gsnedders.html5.org/outliner/ 2.查询是否支持前缀http://caniuse.com 3.border-radius\box-shadow\ ...
- Qt中为QPushButton添加背景图片
有2种方式,一种是在代码中设置,另外一种是直接在Qt Creator中直接设置,下面是第二种 参考: http://doc.qt.io/qt-4.8/stylesheet-examples.html ...
- gitlab利用ssh方式拉取代码
问题1: Bad owner or permissions on .ssh/config的解决 当为本机配一个固定用户名远程登录某主机时,配置了一个config文件,但是在执行ssh免密码登录时报如下 ...
- autoHeight # 动态高度添加 用 window.addEventListener('resize', function () {
动态高度添加 用 window.addEventListener('resize', function () { mounted () { this.init() window.addEventLis ...
- gitee 如何创建仓库 及发布
gitee 如何创建仓库 及发布 http://pengchenggang.gitee.io/layuisyshelp ----------- 在本地项目文件中使用bash $ git config ...
- PHP 中空字符串介绍0、null、empty和false之间的关系
0是数字,是empty,是false,不是null,值相当于空字符串,但类型不是字符串,去空格或强制转换为字符串型时不等于空字符串 ""的值相当于0,是empty,是空字符串,是f ...
- DLL动态链接库的创建
dll的创建主要有两种方法:一是使用 __declspec(dllexport) 创建dll,二是使用模块定义(.def)文件创建dll. 使用 __declspec(dllexport) 创建dll ...
- Ubuntu16.04下安装pip
按照下面的步骤来安装 sudo apt-get install python-setuptools python-dev build-essential 安装python2的pip (要想好你用p ...