CF1618B.Missing Bigram
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp has come up with a new game to play with you. He calls it "A missing bigram".
A bigram of a word is a sequence of two adjacent letters in it.
For example, word "abbaaba" contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".
The game goes as follows. First, Polycarp comes up with a word, consisting only of lowercase letters 'a' and 'b'. Then, he writes down all its bigrams on a whiteboard in the same order as they appear in the word. After that, he wipes one of them off the whiteboard.
Finally, Polycarp invites you to guess what the word that he has come up with was.
Your goal is to find any word such that it's possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.
The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.
波利卡普想出了一个新游戏与你一起玩,他称之为“缺失的二元组”。
一个单词的二元组(bigram)是指该单词中两个相邻的字母所组成的序列。
例如,单词 "abbaaba" 包含二元组 "ab"、"bb"、"ba"、"aa"、"ab" 和 "ba"。
游戏规则如下:首先,波利卡普构思出一个仅由小写字母 'a' 和 'b' 组成的单词;接着,他将该单词中所有二元组按其在单词中出现的顺序依次写在黑板上;然后,他从黑板上擦去其中一个二元组。
最后,波利卡普邀请你猜出他最初构思的单词是什么。
你的目标是找出任意一个单词,使得将其所有二元组按顺序写出后擦去其中一个,所得的二元组序列恰好与波利卡普最终留在黑板上的序列一致。
测试数据保证答案一定存在。若存在多个合法答案,输出任意一个即可。
输入格式
The first line contains a single integer t (1≤t≤2000) — the number of testcases.
The first line of each testcase contains a single integer n (3≤n≤100) — the length of the word Polycarp has come up with.
The second line of each testcase contains n−2 bigrams of that word, separated by a single space. Each bigram consists of two letters, each of them is either 'a' or 'b'.
Additional constraint on the input: there exists at least one string such that it is possible to write down all its bigrams, except one, so that the resulting sequence is the same as the sequence in the input. In other words, the answer exists.
第一行包含一个整数 t(1≤t≤2000)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(3≤n≤100)——Polycarp 构造的单词的长度。
每个测试用例的第二行包含该单词的 n−2 个二元组(bigram),以单个空格分隔。每个二元组由两个字母组成,每个字母均为 'a' 或 'b'。
输入的额外约束:至少存在一个字符串,使得除其中一个二元组外,该字符串的所有二元组按某种顺序排列后,所得序列与输入中的序列完全相同。换言之,答案一定存在。
输出格式
For each testcase print a word, consisting of n letters, each of them should be either 'a' or 'b'. It should be possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.
The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.
对于每个测试用例,输出一个由 n 个字母组成的单词,其中每个字母只能是 'a' 或 'b'。该单词的所有二元字母组合(bigram)应能被写出,并从中移除一个 bigram,使得剩余 bigram 序列与 Polycarp 最终得到的序列完全相同。
测试数据保证答案存在。若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#1
4 7 ab bb ba aa ba 7 ab ba aa ab ba 3 aa 5 bb ab bb
输出#1
abbaaba abaabaa baa bbabb
说明/提示
The first two testcases from the example are produced from the word "abbaaba". As listed in the statement, it contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".
In the first testcase, the 5-th bigram is removed.
In the second testcase, the 2-nd bigram is removed. However, that sequence could also have been produced from the word "abaabaa". It contains bigrams "ab", "ba", "aa", "ab", "ba" and "aa". The missing bigram is the 6-th one.
In the third testcase, all of "baa", "aab" and "aaa" are valid answers.
示例中的前两个测试用例均来自单词 “abbaaba”。如题面所述,它包含二元组(bigram)“ab”、“bb”、“ba”、“aa”、“ab” 和 “ba”。
在第一个测试用例中,第 5 个二元组被移除。
在第二个测试用例中,第 2 个二元组被移除。然而,该序列也可能源自单词 “abaabaa”,它包含二元组 “ab”、“ba”、“aa”、“ab”、“ba” 和 “aa”,缺失的是第 6 个二元组。
在第三个测试用例中,“baa”、“aab” 和 “aaa” 均为有效答案。
输入解题思路,AI测评打分。不知道怎么写?