CF1650A.Deletions of Two Adjacent Letters

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The string ss is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet.

As long as the string length is greater than 11, the following operation can be performed on it: select any two adjacent letters in the string ss and delete them from the string. For example, from the string "lemma" in one operation, you can get any of the four strings: "mma", "lma", "lea" or "lem" In particular, in one operation, the length of the string reduces by 22.

Formally, let the string ss have the form s=s1s2…sns=s_1s_2 \dots s_n (n>1n \gt 1). During one operation, you choose an arbitrary index ii (1≤i<n1 \le i \lt n) and replace s=s1s2…si−1si+2…sns=s_1s_2 \dots s_{i-1}s_{i+2} \dots s_n.

For the given string ss and the letter cc, determine whether it is possible to make such a sequence of operations that in the end the equality s=cs=c will be true? In other words, is there such a sequence of operations that the process will end with a string of length 11, which consists of the letter cc?

给定字符串 ss,其长度为奇数。字符串 ss 仅由拉丁字母表中的小写字母组成。

只要字符串长度大于 11,就可以对其执行如下操作:在字符串 ss 中任选两个相邻的字母,并将它们从字符串中删除。例如,对字符串 “lemma” 执行一次操作,可得到以下四个字符串之一:“mma”、“lma”、“lea” 或 “lem”。特别地,每次操作会使字符串长度减少 22。

形式化地,设字符串 ss 的形式为 s=s1s2…sns=s_1s_2 \dots s_n(其中 n>1n \gt 1)。在一次操作中,任选一个下标 ii(满足 1≤i<n1 \le i \lt n),并将 ss 替换为 s1s2…si−1si+2…sns_1s_2 \dots s_{i-1}s_{i+2} \dots s_n。

对于给定的字符串 ss 和字母 cc,判断是否存在一系列上述操作,使得最终得到的字符串恰好为 s=cs=c?换言之,是否存在一系列操作,使得该过程最终终止于一个长度为 11 的字符串,且该字符串仅由字母 cc 构成?

输入格式

The first line of input data contains an integer tt (1≤t≤1031 \le t \le 10^3) — the number of input test cases.

The descriptions of the tt cases follow. Each test case is represented by two lines:

  • string ss, which has an odd length from 11 to 4949 inclusive and consists of lowercase letters of the Latin alphabet;
  • is a string containing one letter cc, where cc is a lowercase letter of the Latin alphabet.

输入数据的第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3)—— 表示输入测试用例的数量。

接下来是 tt 个测试用例的描述。每个测试用例由两行组成:

  • 字符串 ss,其长度为奇数,取值范围为 11 到 4949(含端点),且仅由小写拉丁字母组成;
  • 一个仅包含单个字母 cc 的字符串,其中 cc 为小写拉丁字母。

输出格式

For each test case in a separate line output:

  • YES, if the string ss can be converted so that s=cs=c is true;
  • NO otherwise.

You can output YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive response).

对于每个测试用例,在单独的一行中输出:

  • 如果字符串 ss 可以被转换为使得 s=cs=c 成立,则输出 YES;
  • 否则输出 NO。

YES 和 NO 的大小写不限(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    5
    abcde
    c
    abcde
    b
    x
    y
    aaaaaaaaaaaaaaa
    a
    contest
    t

    输出#1

    YES
    NO
    NO
    YES
    YES

说明/提示

In the first test case, ss="abcde". You need to get ss="c". For the first operation, delete the first two letters, we get ss="cde". In the second operation, we delete the last two letters, so we get the expected value of ss="c".

In the third test case, ss="x", it is required to get ss="y". Obviously, this cannot be done.

在第一个测试用例中,ss = "abcde",你需要得到 ss = "c"。第一次操作中,删除前两个字母,得到 ss = "cde";第二次操作中,删除最后两个字母,从而得到期望的 ss = "c"。

在第三个测试用例中,ss = "x",要求得到 ss = "y"。显然,这是不可能的。

输入解题思路,AI测评打分。不知道怎么写?

首页