CF754C.Vladik and chat
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.
At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. In particular, some of the messages have no information of their sender. It is known that if a person sends several messages in a row, they all are merged into a single message. It means that there could not be two or more messages in a row with the same sender. Moreover, a sender never mention himself in his messages.
Vladik wants to recover senders of all the messages so that each two neighboring messages will have different senders and no sender will mention himself in his messages.
He has no idea of how to do this, and asks you for help. Help Vladik to recover senders in each of the chats!
最近,Vladik 发现了一种新的娱乐方式——为社交网络编写机器人。他希望在自己的机器人中应用机器学习,因此现在需要准备一些用于训练的数据。
首先,他需要下载 t 个聊天记录。Vladik 编写了一个脚本用于下载这些聊天记录,但出现了某些问题。具体而言,部分消息缺失了发送者信息。已知:如果某人连续发送多条消息,则这些消息会被合并为一条消息。这意味着不可能存在两条或以上连续的消息具有相同的发送者。此外,发送者绝不会在自己的消息中提及自己。
Vladik 希望恢复所有消息的发送者,使得任意两条相邻消息的发送者均不相同,且每位发送者均未在自己的消息中提及自己。
他完全不知道该如何实现这一点,于是向你求助。请帮助 Vladik 恢复每个聊天记录中各条消息的发送者!
输入格式
The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format.
The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat.
The next line contains n space-separated distinct usernames. Each username consists of lowercase and uppercase English letters and digits. The usernames can't start with a digit. Two usernames are different even if they differ only with letters' case. The length of username is positive and doesn't exceed 10 characters.
The next line contains single integer m (1 ≤ m ≤ 100) — the number of messages in the chat. The next m line contain the messages in the following formats, one per line:
: — the format of a message with known sender. The username should appear in the list of usernames of the chat. -
>:
— the format of a message with unknown sender.
The text of a message can consist of lowercase and uppercase English letter, digits, characters '.' (dot), ',' (comma), '!' (exclamation mark), '?' (question mark) and ' ' (space). The text doesn't contain trailing spaces. The length of the text is positive and doesn't exceed 100 characters.
We say that a text mention a user if his username appears in the text as a word. In other words, the username appears in a such a position that the two characters before and after its appearance either do not exist or are not English letters or digits. For example, the text "Vasya, masha13 and Kate!" can mention users "Vasya", "masha13", "and" and "Kate", but not "masha".
It is guaranteed that in each chat no known sender mention himself in his messages and there are no two neighboring messages with the same known sender.
第一行包含一个整数 t(1≤t≤10)—— 聊天室的数量。接下来是 t 个聊天室的描述,每个聊天室按如下格式给出。
每个聊天室描述的第一行包含一个整数 n(1≤n≤100)—— 该聊天室中的用户数量。
下一行包含 n 个由空格分隔的、互不相同的用户名。每个用户名由小写和大写英文字母以及数字组成;用户名不能以数字开头。即使仅大小写不同,两个用户名也被视为不同。用户名长度为正整数,且不超过 10 个字符。
接下来的一行包含一个整数 m(1≤m≤100)—— 该聊天室中消息的数量。随后的 m 行每行包含一条消息,格式如下:
<username>:<text>—— 发送者已知的消息格式。其中username必须出现在该聊天室的用户名列表中。<?>:<text>—— 发送者未知的消息格式。
消息正文 text 可由小写和大写英文字母、数字、字符 .(句点)、,(逗号)、!(感叹号)、?(问号)以及空格 ' ' 组成。正文末尾不含多余空格。正文长度为正整数,且不超过 100 个字符。
我们称一段正文“提及”某用户,当且仅当该用户的用户名作为一个独立单词出现在正文中。换言之,用户名出现的位置满足:其前一个字符与后一个字符均不存在,或均不是英文字母或数字。例如,正文 "Vasya, masha13 and Kate!" 可提及用户 "Vasya"、"masha13"、"and" 和 "Kate",但不提及 "masha"。
保证在每个聊天室中:
- 没有已知发送者在其自己的消息中提及自己;
- 不存在两条相邻消息具有相同的已知发送者。
输出格式
Print the information about the t chats in the following format:
If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format:
If there are multiple answers, print any of them.
按以下格式输出 t 个聊天的信息:
若无法恢复发送者,则对此聊天单独输出一行 "Impossible"。否则,按以下格式输出 m 条消息:
<用户名>:<文本>
若存在多个可行答案,输出任意一个即可。
输入输出样例
输入#1
1 2 Vladik netman 2 ?: Hello, Vladik! ?: Hi
输出#1
netman: Hello, Vladik! Vladik: Hi
输入#2
1 2 netman vladik 3 netman:how are you? ?:wrong message vladik:im fine
输出#2
Impossible
输入#3
2 3 netman vladik Fedosik 2 ?: users are netman, vladik, Fedosik vladik: something wrong with this chat 4 netman tigerrrrr banany2001 klinchuh 4 ?: tigerrrrr, banany2001, klinchuh, my favourite team ever, are you ready? klinchuh: yes, coach! ?: yes, netman banany2001: yes of course.
输出#3
Impossible netman: tigerrrrr, banany2001, klinchuh, my favourite team ever, are you ready? klinchuh: yes, coach! tigerrrrr: yes, netman banany2001: yes of course.
输入解题思路,AI测评打分。不知道怎么写?