QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#257. 光通信

Statistics

飞机失事后,71 名幸存者被困在一座荒岛上。他们最终开始探索岛屿,并制定了一套长距离通信策略以辅助探索。他们利用残骸中找到的镜子,通过摩尔斯电码反射阳光进行通信。遗憾的是,这要求通信双方必须处于视线范围内。

岛上有几个绝佳的观测点,可以俯瞰岛屿的大部分区域,这些观测点对于中继消息非常有用。每个观测点都有一个哨所,时刻有幸存者值守。该幸存者负责发送新消息,并将收到的消息中继给所有其他可见的哨所。如果哨所收到的消息是其已经发送或接收过的,则该消息会被忽略,不再视为新接收(幸存者们制定了一套识别消息的系统)。

由于树木、山脉等障碍物,或雨、雾等天气原因,能够直接看到消息的幸存者集合会发生变化。请编写一个程序,输出在每种场景下每位幸存者收到的消息列表。在每个测试用例开始时,假设没有任何人能看到其他人的消息。

输入格式

输入的第一行包含测试用例的数量 $T$ ($1 \leq T \leq 50$)。

每个测试用例的第一行包含事件的数量 $E$ ($1 \leq E \leq 50$)。接下来的 $E$ 行中,每一行包含以下事件之一:

  • VISIBLE A B:幸存者 A 和幸存者 B 可以互相看见。
  • OBSTACLE A B:由于障碍物,幸存者 A 和幸存者 B 不再能互相看见。
  • WEATHER A B:由于天气原因,幸存者 A 和幸存者 B 不再能互相看见。
  • MESSAGE A "HELLO":幸存者 A 向所有其他可见的哨所发送消息 HELLO

每位幸存者由一个字符 A-Z 表示。

每条消息包含至少 1 个、最多 100 个字符,字符集由 A-Z 和空格组成。消息总是被一对引号 (") 包围。

输出格式

对于每个测试用例,输出每位收到消息的幸存者的情况,按幸存者字母顺序排序。

每一行的格式为 A: ["MSG I", "MSG II"],其中 A 是接收者的字母,"MSG I", "MSG II" 是该幸存者收到的消息列表(每条消息均加引号),以逗号和空格分隔。如果某位幸存者收到的消息数为零,则不要为其打印该行。

每位幸存者收到的消息应按接收顺序打印。

在两个测试用例之间打印一个空行。

样例

输入 1

2
6
VISIBLE B A
MESSAGE A "HELLO"
WEATHER A B
MESSAGE A "GOODBYE"
VISIBLE A B
MESSAGE A "WORLD"
11
VISIBLE B A
VISIBLE C A
VISIBLE D A
VISIBLE E A
VISIBLE F A
VISIBLE G H
MESSAGE A "YOU"
MESSAGE B "ARE"
OBSTACLE B A
MESSAGE C "NOT"
MESSAGE G "ALONE"

输出 1

B: ["HELLO", "WORLD"]

A: ["ARE", "NOT"]
B: ["YOU"]
C: ["YOU", "ARE"]
D: ["YOU", "ARE", "NOT"]
E: ["YOU", "ARE", "NOT"]
F: ["YOU", "ARE", "NOT"]
H: ["ALONE"]

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.