CF1922A.Tricky Template

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer nn and three strings a,b,ca, b, c, each consisting of nn lowercase Latin letters.

Let a template be a string tt consisting of nn lowercase and/or uppercase Latin letters. The string ss matches the template tt if the following conditions hold for all ii from 11 to nn:

  • if the ii-th letter of the template is lowercase, then sis_i must be the same as tit_i;
  • if the ii-th letter of the template is uppercase, then sis_i must be different from the lowercase version of tit_i. For example, if there is a letter 'A' in the template, you cannot use the letter 'a' in the corresponding position of the string.

Accordingly, the string doesn't match the template if the condition doesn't hold for at least one ii.

Determine whether there exists a template tt such that the strings aa and bb match it, while the string cc does not.

给你一个整数 nn 和三个字符串 a,b,ca, b, c,每个字符串均由 nn 个小写拉丁字母组成。

定义一个模板为一个长度为 nn 的字符串 tt,其中每个字符可以是小写或大写的拉丁字母。字符串 ss 匹配模板 tt,当且仅当对所有 ii(从 11 到 nn)均满足以下条件:

  • 若模板的第 ii 个字符为小写字母,则 sis_i 必须与 tit_i 完全相同;
  • 若模板的第 ii 个字符为大写字母,则 sis_i 必须不同于 tit_i 的小写形式。例如,若模板中某位置为字母 'A',则对应位置的字符串中不能使用字母 'a'。

相应地,若存在至少一个 ii 不满足上述条件,则称字符串 ss 不匹配该模板。

请判断:是否存在一个模板 tt,使得字符串 aa 和 bb 均匹配 tt,而字符串 cc 不匹配 tt。

输入格式

The first line contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains an integer nn (1≤n≤201 \le n \le 20) — the length of the given strings.

The next three lines contain the strings a,ba, b and cc. Each string consists of exactly nn lowercase Latin letters.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤201 \le n \le 20)—— 给定字符串的长度。

接下来三行分别包含字符串 aa、bb 和 cc。每个字符串均由恰好 nn 个小写拉丁字母组成。

输出格式

For each testcase, print "YES" if there exists a template tt such that the strings aa and bb match it, while the string cc does not. Otherwise, print "NO".

对于每个测试用例,如果存在一个模板 tt,使得字符串 aa 和 bb 均能匹配该模板,而字符串 cc 不能匹配,则输出 "YES";否则输出 "NO"。

输入输出样例

  • 输入#1

    4
    1
    a
    b
    c
    2
    aa
    bb
    aa
    10
    mathforces
    luckforces
    adhoccoder
    3
    acc
    abd
    abc

    输出#1

    YES
    NO
    YES
    NO

说明/提示

In the first test case, you can use the template "C". The first letter of strings aa and bb differ from 'c', so they match the template. The first letter of string cc equals 'c', so it doesn't match.

In the third test case, you can use the template "CODEforces".

在第一个测试用例中,你可以使用模板 “C”。字符串 aa 和 bb 的首字母均不为 'c',因此它们与该模板匹配;而字符串 cc 的首字母为 'c',因此不匹配。

在第三个测试用例中,你可以使用模板 “CODEforces”。

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

首页