QOJ.ac

QOJ

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

#20916. 猜動物

Statistics

厭倦平常的猜杯子遊戲時,奶牛 Bessie 和朋友 Elsie 喜歡玩另一種常見遊戲「猜動物」。

首先 Bessie 想一種動物(大多數時候是奶牛,所以遊戲相當無聊,但偶爾也會發揮創意,想其他動物)。然後 Elsie 連續提問,以確定選了什麼動物。每個問題詢問動物是否具有某個特徵,Bessie 回答「是」或「否」。例如:

Elsie: "這動物會飛嗎?"
Bessie: "否"
Elsie: "這動物吃草嗎?"
Bessie: "是"
Elsie: "這動物產奶嗎?"
Bessie: "是"
Elsie: "這動物會哞哞叫嗎?"
Bessie: "是"
Elsie: "那麼我認為牠是奶牛。"
Bessie: "正確!"

如果將與 Elsie 迄今提問結果一致的所有動物稱為「可行集合」,她會持續提問直到集合僅剩一種動物,然後宣布該動物為答案。每次她選擇可行集合中某動物具有的特徵來問,即使這可能無法進一步縮小集合。她從不重複詢問同一特徵。

給定她們知道的所有動物及其特徵,求 Elsie 在知道正確動物之前最多可能收到多少次「是」的回答。

輸入格式

從標準輸入讀取。

第一行包含動物數 $N$($2 \leq N \leq 100$)。接下來 $N$ 行各描述一種動物:先是動物名,再是整數 $K$($1 \leq K \leq 100$),然後是它的 $K$ 個特徵。名稱和特徵都是長度不超過 20 的小寫字母字串(a..z)。沒有兩種動物的特徵完全相同。

輸出格式

將結果寫到標準輸出。

輸出遊戲結束前 Elsie 最多可能收到的「是」的回答次數。

範例

輸入格式 1

4
bird 2 flies eatsworms
cow 4 eatsgrass isawesome makesmilk goesmoo
sheep 1 eatsgrass
goat 2 makesmilk eatsgrass

輸出格式 1

3

說明

範例中可以產生 3 次「是」的對話記錄(如上所示),而無法產生超過 3 次「是」的記錄。

題目作者: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.