QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 256 MB 총점: 100

#20943. 牲畜排隊

통계

Farmer John 每天為八頭乳牛擠奶,名字為 Bessie, Buttercup, Belinda, Beatrice, Bella, Blue, Betsy, Sue。

不幸的是,乳牛們很挑剔,要求順序滿足 $N$ 條限制($1 \leq N \leq 7$)。每條形式為「$X$ 必須緊鄰 $Y$ 擠奶」,即 $X$ 必須緊接在 $Y$ 前面或後面。

請找出滿足所有限制的順序。保證總有解。若有多種,輸出按字母序最先的:第一頭是在所有合法順序中能排第一的乳牛裡名字最小的;在第一頭相同的合法順序中,再選名字最小的第二頭,依此類推。

輸入格式

第一行包含 $N$。接下來 $N$ 行,每行一個形如 X must be milked beside Y 的句子描述限制,其中 $X$、$Y$ 是上面八個名字之一。

輸出格式

輸出 8 行,每行一頭乳牛,表示滿足所有限制的順序。若有多種,輸出按字母序最先的。

範例

輸入格式 1

3
Buttercup must be milked beside Bella
Blue must be milked beside Bella
Sue must be milked beside Beatrice

輸出格式 1

Beatrice
Sue
Belinda
Bessie
Betsy
Blue
Bella
Buttercup

題目署名:Brian Dean

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.