592-island of Logic
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_ problem&problem=533
The Island of Logic has three kinds of inhabitants:divine beings that always tell the truth, evil beings so always lie, and human beings that are truthful during the "Day" and lie at night. Every inhabitant recognizes the type of Every other inhabitant.
A social scientist wants to visit the island. Because he isn't able to distinguish the three kinds of beings-only-their looks, he asks to provide a communicat Ion Analyzer that deduces facts from conversations among inhabitants. The interesting facts are whether it is day or night and what kind of beings the speakers.
Input
The input file contains several descriptions of conversations. Each description starts with a integer n, the number of statements in the conversation. The following n lines each contain one statement by a inhabitant. Every statement Line begins with the speaker's name, one of the capital letters A, B, C, D, E, followed by A Colon ': '. Next is one of the following kinds of statements:
I AM [NOT] (Divine | human | evil | lying).
X is [not] (Divine | human | evil | lying).
It is (day | night).
Square brackets [] mean the word in the brackets or may is not appear, round brackets () mean that exactly one of th E Alternatives separated by | Must appear. X stands for some name from A, B, C, D, E. There'll be no two consecutive spaces into any statement line, and at most statements in a conversation.
The input is terminated by a test case starting with n = 0.
Output
For each conversation, the ' conversation in the ' format shown in the sample output. Then print ' is impossible. ', if the conversation cannot happen according to the rules or ' No facts are. ' ', if no facts can be deduced. Otherwise print all the facts so can be deduced. Deduced facts should be printed using the following formats:
X Is (Divine | human | evil).
It is (day | night).
X is to being replaced by a capital letter speaker name. Facts about inhabitants must be given a, alphabetical it may be then stated it are day or whether.
The output for each conversation must is followed by a single blank line.
Sample Input
1
a:i am Divine.
1
a:i am lying.
1
a:i am evil.
3
a:b is human.
B:a is evil.
A:b is evil.
0
Sample Output
Conversation #1
No facts are deducible.
Conversation #2 This is
impossible.
Conversation #3
A is human.
It is night.
Conversation #4
A is evil.
B is divine.
Reasoning Made Easy
To make things clearer, we'll show the reasoning behind the third input example, where A says ' I am evil. What can be deduced from this? Obviously a cannot is divine, since she would be lying, similarly a cannot is evil, since she would tell the truth. Therefore, A must be human, moreover, since she is lying, it must to be night. So the correct output is as shown.
In the fourth input example, it are obvious that A is lying since her two statements are. So, B can is neither human nor evil, and consequently must be divine. B always tells the truth, thus A must be evil. Voil ' A!