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 ...
随机推荐
- VC中常用的宏[转]
我们在VS环境中开发的时候,会遇到很多宏定义,这些宏可以应用到代码中,或用于编译.工程选项等设置,总之是我们开发中必不可少的工具,有必要做一个总结.有些宏是C/C++定义的,有些宏是VC环境预定义的. ...
- Libvirt 网络管理
- js 数组去重 的5种方法
一万数组,4个重复项,先贴上成绩. 1.3毫秒 2.115毫秒 3.71毫秒 4.6毫秒 1.哈希表 2.JQuery (最快的方法是用JQuery 这句话是截图带的... 实际上Jq是最慢的) 3. ...
- Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd
http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...
- cdoj 65 CD Making 水题
CD Making Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/65 De ...
- 安卓高手之路之 WindowManager
安卓中的画面不是纯粹由window组成.而是改成了window+view的组织模式.window是一个顶层窗口的概念.view就相当于在window内的控件.而subwindow则是依附于window ...
- 推荐安卓开发神器(里面有各种UI特效和实例)
网上有很多开源的安卓类库很好用,对于刚学习安卓的童鞋亦或者老鸟都是很好的学习对象. 我平时有关注开源代码的习惯,这么多年也搜集了不少精彩的源码. 到后来发现自己手机里装的都是几百个demo app,删 ...
- 关于View端
View--------------Request 1 URL vs n View 同一个URL可以对应多个View, HTML(通过Request请求获得) 例如SAO项目中的step1--> ...
- document.createElement("A");
搞了一天,终于把A里面的属性弄出来 代码1: <BODY></BODY><SCRIPT LANGUAGE="JavaScript"><!- ...