CF1662B.Toys

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vittorio has three favorite toys: a teddy bear, an owl, and a raccoon. Each of them has a name.

Vittorio takes several sheets of paper and writes a letter on each side of every sheet so that it is possible to spell any of the three names by arranging some of the sheets in a row (sheets can be reordered and flipped as needed). The three names do not have to be spelled at the same time, it is sufficient that it is possible to spell each of them using all the available sheets (and the same sheet can be used to spell different names).

Find the minimum number of sheets required. In addition, produce a list of sheets with minimum cardinality which can be used to spell the three names (if there are multiple answers, print any).

维托里奥有三个最喜爱的玩具:一只泰迪熊、一只猫头鹰和一只浣熊。每个玩具都有一个名字。

维托里奥取若干张纸,每张纸的正反两面各写一个字母,使得通过将其中一些纸张排成一列(纸张可以重新排序,也可以翻转),能够拼写出这三个名字中的任意一个。这三个名字无需同时拼写;只要利用所有可用的纸张(同一张纸可用于拼写不同的名字),能分别拼写出每一个名字即可。

求所需的最少纸张数量。此外,请给出一组达到该最小数量的纸张列表(若存在多种答案,输出任意一种即可)。

输入格式

The first line contains a string tt consisting of uppercase letters of the English alphabet (1≤∣t∣≤10001\le |t| \le 1000) — the name of the teddy bear.

The second line contains a string oo consisting of uppercase letters of the English alphabet (1≤∣o∣≤10001\le |o| \le 1000) — the name of the owl.

The third line contains a string rr consisting of uppercase letters of the English alphabet (1≤∣r∣≤10001\le |r| \le 1000) — the name of the raccoon.

The values ∣t∣|t|, ∣o∣|o|, ∣r∣|r| denote the length of the three names tt, oo, rr.

第一行包含一个由英文字母大写组成的字符串 tt(1≤∣t∣≤10001\le |t| \le 1000)——泰迪熊的名字。

第二行包含一个由英文字母大写组成的字符串 oo(1≤∣o∣≤10001\le |o| \le 1000)——猫头鹰的名字。

第三行包含一个由英文字母大写组成的字符串 rr(1≤∣r∣≤10001\le |r| \le 1000)——浣熊的名字。

其中,∣t∣|t|、∣o∣|o|、∣r∣|r| 分别表示三个名字 tt、oo、rr 的长度。

输出格式

The first line of the output contains a single integer mm — the minimum number of sheets required.

Then mm lines follow: the jj-th of these lines contains a string of two uppercase letters of the English alphabet — the letters appearing on the two sides of the jj-th sheet.

Note that you can print the sheets and the two letters of each sheet in any order.

输出的第一行包含一个整数 mm —— 所需纸张的最少数量。

随后是 mm 行:其中第 jj 行包含一个由两个大写英文字母组成的字符串 —— 表示第 jj 张纸正反两面的字母。

注意:你可以以任意顺序输出纸张,且每张纸上的两个字母也可按任意顺序输出。

输入输出样例

  • 输入#1

    AA
    GA
    MA

    输出#1

    2
    AG
    AM
  • 输入#2

    TEDDY
    HEDWIG
    RACCOON

    输出#2

    8
    AT
    CH
    CY
    DG
    DO
    ER
    IN
    OW
  • 输入#3

    BDC
    CAA
    CE

    输出#3

    4
    AD
    AE
    BB
    CC

说明/提示

In the first sample, the solution uses two sheets: the first sheet has A on one side and G on the other side; the second sheet has A on one side and M on the other side.

The name AA can be spelled using the A side of both sheets. The name GA can be spelled using the G side of the first sheet and the A side of the second sheet. Finally, the name MA can be spelled using the M side of the second sheet and the A side of the first sheet.

在第一个样例中,解决方案使用了两张纸片:第一张纸片的一面是 A,另一面是 G;第二张纸片的一面是 A,另一面是 M。

名字 AA 可以通过使用两张纸片的 A 面拼出;
名字 GA 可以通过使用第一张纸片的 G 面和第二张纸片的 A 面拼出;
最后,名字 MA 可以通过使用第二张纸片的 M 面和第一张纸片的 A 面拼出。

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

首页