CF Two Substrings
2 seconds
256 megabytes
standard input
standard output
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
ABA
NO
BACFAB
YES
AXBYBXA
NO 找到每组AB和BA的起点坐标,保存起来,然后用最远的一个BA的坐标减去最近的一个AB,或者最远的一个AB减去一个最近的BA,如果两者的差大于等于2,那么就YES.
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; int main(void)
{
char s[];
int ab[],ba[];
int p_ab = ,p_ba = ; scanf("%s",s);
for(int i = ;s[i];i ++)
{
if(s[i] == 'A' && s[i + ] == 'B')
{
ab[p_ab] = i;
p_ab ++;
}
else if(s[i] == 'B' && s[i + ] == 'A')
{
ba[p_ba] = i;
p_ba ++;
}
}
if(!p_ab || !p_ba)
{
puts("NO");
return ;
}
sort(ab,ab + p_ab);
sort(ba,ba + p_ba);
if(abs(ab[] - ba[p_ba - ]) >= || abs(ba[] - ab[p_ab - ]) >= )
puts("YES");
else
puts("NO"); return ;
}
CF Two Substrings的更多相关文章
- CF 914F Substrings in a String——bitset处理匹配
题目:http://codeforces.com/contest/914/problem/F 可以对原字符串的每种字母开一个 bitset .第 i 位的 1 表示这种字母在第 i 位出现了. 考虑能 ...
- shift and算法
1. CF 914F Substrings in a String 大意: 给定一个串s, q个询问, (1)单点修改, (2)询问[l,r]范围内串y的出现次数. shift and算法板子题 #p ...
- CF 1400F x-prime Substrings 题解【AC自动机+DP】
CF 1400F.x-prime Substrings 题意: 给定一个由\('1'\)到\('9'\)组成的字符串\(s\)和一个数\(x\),定义一个串为\(x-prime\)串,当且仅当这个串上 ...
- [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】
题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...
- CF 316G3 Good Substrings——广义后缀自动机
题目:http://codeforces.com/contest/316/problem/G3 对询问串和模式串一起建一个后缀自动机,做出在每个串上的 right 集合大小之后枚举自动机上的每个点看看 ...
- CF 917A The Monster 【括号匹配】
[链接]:CF Examples inputCopy ((?)) outputCopy 4 inputCopy ??()?? outputCopy 7 说明 For the first sample ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Codeforces CF#628 Education 8 B. New Skateboard
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- JavaScript一些不常用的写法
如何写JavaScript才能逼格更高呢?怎样才能组织JavaScript才能让别人一眼看出你不简单呢?是否很期待别人在看完你的代码之后感叹一句“原来还可以这样写”呢?下面列出一些在JavaScrip ...
- 【转】Android 实现蘑菇街购物车动画效果
原文出处:http://blog.csdn.net/wangjinyu501/article/details/38400479 1.思路 目前想到两种方式实现这种效果,一是使用Tween动画,直截 ...
- 圣杯VS双飞翼
双飞翼: <!DOCTYPE html> <html> <head> <title>推荐封面</title> <meta name=& ...
- 用Javascript编写Chrome浏览器插件
原文:http://homepage.yesky.com/62/11206062.shtml 用Javascript编写Chrome浏览器插件 2010-04-12 07:30 来源:天极网软件频道 ...
- visual studio 设计器上出现蓝色的点和箭头
visual studio 设计器上出现蓝色的点和箭头: 突然发现打开visual studio 的时候出现了很多蓝色的点和箭头,解决办法是:按组合快捷键 Ctrl+R,Ctrl+W 或 Ctrl+E ...
- 【C#】工具类-FTP操作封装类FTPHelper
转载:http://blog.csdn.net/gdjlc/article/details/11968477 using System; using System.Collections.Generi ...
- uva140 - Bandwidth
Bandwidth Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and an orderi ...
- Linux磁盘及文件系统管理 4---- Linux文件系统挂载管理
1 挂载操作 1 磁盘或者分区需要创建好文件系统后,需要挂载到一个目录才能够使用 2 windows或者是Mac会自动的挂载文件系统,一旦创建好文件系统后会自动的挂载 3 对于Linux来说我们必须要 ...
- Java Web模块——验证码模块
一.什么是验证码及它的作用 验 证码为全自动区分计算机和人类的图灵测试的缩写,是一种区分用户是计算机的公共全自动程序,这个问题可以由计算机生成并评判,但是必须只有人类才能解答. 可以防止恶意破解密码. ...
- SQL SERVER中查找某关键词位于哪些存储过程或函数
USE [MYDB] go SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_type='PROCEDURE' AND routine_d ...