CF1579A.Casimir's String Solitaire
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Casimir has a string s which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions:
- he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent);
- or he can erase exactly one letter 'B' and exactly one letter 'C' from arbitrary places in the string (these letters don't have to be adjacent).
Therefore, each turn the length of the string is decreased exactly by 2. All turns are independent so for each turn, Casimir can choose any of two possible actions.
For example, with s = "ABCABC" he can obtain a string s = "ACBC" in one turn (by erasing the first occurrence of 'B' and the second occurrence of 'A'). There are also many other options for a turn aside from this particular example.
For a given string s determine whether there is a sequence of actions leading to an empty string. In other words, Casimir's goal is to erase all letters from the string. Is there a way to do this?
卡西米尔有一个字符串 s,该字符串仅由大写拉丁字母 'A'、'B' 和 'C' 组成。每一轮他可以选择执行以下两种操作之一:
- 他可以恰好擦除一个字母 'A' 和一个字母 'B'(这两个字母可以位于字符串中任意位置,不必相邻);
- 或者他可以恰好擦除一个字母 'B' 和一个字母 'C'(这两个字母可以位于字符串中任意位置,不必相邻)。
因此,每轮操作后字符串的长度恰好减少 2。各轮操作相互独立,即在每一轮中,卡西米尔均可自由选择上述两种操作中的任意一种。
例如,对于 $s = $ "ABCABC",他可以在一轮操作中得到字符串 $s = $ "ACBC"(通过擦除第一个出现的 'B' 和第二个出现的 'A')。除该示例外,每轮操作还有许多其他可行的选择。
给定字符串 s,请判断是否存在一系列操作使得最终字符串变为空串。换言之,卡西米尔的目标是将字符串中的所有字母全部擦除。是否存在这样一种操作方案?
输入格式
The first line contains an integer t (1≤t≤1000) — the number of test cases.
Each test case is described by one string s, for which you need to determine if it can be fully erased by some sequence of turns. The string s consists of capital letters 'A', 'B', 'C' and has a length from 1 to 50 letters, inclusive.
第一行包含一个整数 t(1≤t≤1000)—— 测试用例的数量。
每个测试用例由一个字符串 s 描述,你需要判断该字符串是否能通过某种操作序列被完全擦除。字符串 s 仅由大写字母 'A'、'B'、'C' 组成,长度为 1 至 50(含端点)。
输出格式
Print t lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if there is a way to fully erase the corresponding string and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).
输出 t 行,每行包含对应测试用例的答案。若存在一种方式可以完全擦除对应的字符串,则答案为 YES;否则为 NO。
你可以以任意大小写形式输出每个字母(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。
输入输出样例
输入#1
6 ABACAB ABBA AC ABC CABCBB BCBCBCBCBCBCBCBC
输出#1
NO YES NO NO YES YES
输入解题思路,AI测评打分。不知道怎么写?