codeforces #306 div 2 A – Two Substrings(随便搞)

A – Two Substrings

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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).

Input

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Output

Print “YES” (without the quotes), if string s contains two non-overlapping substrings “AB” and “BA”, and “NO” otherwise.

Sample Input

Input

Output

Input

Output

Input

Output

Hint

In the first sample test, despite the fact that there are substrings “AB” and “BA”, their occurrences overlap, so the answer is “NO”.

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring “AB” nor substring “BA”.

 

 

这题竟然wa了四次…

我发现如果最开始做一道题没想清楚的话…即使过了若干天后重新想..也特别容易wa…?

我们可以直接考虑覆盖概率最小的情况.就是最边缘.

分为两种情况,一种是xxxxABxxxxBAxxxx

一中是xxxxBAxxxxxABxxxxx

注意找到记录的一定是最边缘的位置!找到相应的break掉也好加个判断也好…

View Code

 

Posted in ACM

说点什么

您将是第一位评论人!

提醒
wpDiscuz