Island of Logic 

The Island of Logic has three kinds of inhabitants: divine beings that always tell the truth, evil beings that 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 is not able to distinguish the three kinds of beings only from their looks, he asks you to provide a communication 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 are.

Input

The input file contains several descriptions of conversations. Each description starts with an integer 
n
, the number of statements in the conversation. The following 
n
 lines each contain one statement by an 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 that the word in the brackets may or may not appear, round brackets () mean that exactly one of the alternatives separated by |must appear. X stands for some name from ABCDE. There will be no two consecutive spaces in any statement line, and at most 50 statements in a conversation.

The input is terminated by a test case starting with n = 0.

Output

For each conversation, first output the number of the conversation in the format shown in the sample output. Then print ``
This is impossible.
'', if the conversation cannot happen according to the rules or ``
No facts are deducible.
'', if no facts can be deduced. Otherwise print all the facts that can be deduced. Deduced facts should be printed using the following formats:

  • X is ( divine | human | evil ).
  • It is ( day | night ).

X is to be replaced by a capital letter speaker name. Facts about inhabitants must be given first (in alphabetical order), then it may be stated whether it is day or night.

The output for each conversation must be 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.

题目大意:一个逻辑岛上住有人类,恶魔和神,恶魔总是说谎话,人在白天说真话,在晚上说假话,神一直说真话,现在给出一些人说的话,从中判断并且输出可以确定的信息。

解题思路:将所有语句存成结构体的形式,只需要记录说话人,被说人,说话肯否定(not),和对象。处理方法就是将所有情况列举出来,然后将语句进行判断。如果出现两组满足,就将两组中相同的保留(这些是可以确定的)

注意:即使没有人类被确定,但是白天黑夜已经被分出来了,也要输出。

提供一些数据:

6
A: B is human.
A: B is evil.
B: A is human.
C: A is not lying.
B: C is not human.
D: E is not lying.
4
A: I am human.
A: It is night.
B: I am human.
B: It is day.
3
A: I am human.
B: I am human.
A: B is lying.
3
A: I am divine.
B: A is not lying.
A: B is lying.
3
A: I am divine.
B: A is lying.
A: B is lying.
5
A: B is human.
A: B is evil.
B: A is evil.
C: A is not lying.
B: It is day.
5
C: A is not lying.
A: B is human.
A: B is evil.
B: A is evil.
B: It is day.
1
A: A is not lying.
1
A: A is lying.
2
E: E is evil.
E: E is divine.
7
A: It is night.
B: It is day.
C: I am human.
E: C is human.
C: E is divine.
A: B is lying.
B: C is evil.
0

*********************************************************************************

Conversation #1
A is human.
B is divine.
C is evil.
It is night.

Conversation #2
A is evil.
B is human.
It is day.

Conversation #3
It is day.

Conversation #4
This is impossible.

Conversation #5
No facts are deducible.

Conversation #6
A is evil.
B is divine.
C is evil.
It is day.

Conversation #7
A is evil.
B is divine.

C is evil.
It is day.

Conversation #8
No facts are deducible.

Conversation #9
This is impossible.

Conversation #10
E is human.
It is night.

Conversation #11
A is evil.
C is evil.
E is evil.
It is day.

********************************************************************************

#include<iostream>
#include<string.h>
using namespace std; #define N 55
#define M 10 int people[M];
int brith[M];
int n;
int ok;
int FP;
int now[M];
int yes[M]; struct say{
char talk;
char name;
int bo;
int sex;
}; void thesome()
{
for(int i = 0; i < 6; i++)
if(now[i] != people[i])
yes[i] = 1;
} int ture_say(say f)
{
if(f.sex != -1)
{
if(f.name == 'T')
{
if(f.bo && f.sex - 4 == people[0])
return 1;
else if(!f.bo && f.sex - 4 != people[0])
return 1;
else
return 0;
}
else
{
int id = f.name - 'A' + 1;
if(f.bo && f.sex == people[id])
return 1;
else if(!f.bo && f.sex != people[id])
return 1;
else
return 0;
}
}
else
{
int id = f.name - 'A' + 1; if(people[id] == 3 && !f.bo)
return 1;
else if (people[id] == 1 && f.bo)
return 1;
else if(people[id] == 2)
{
if(people[0] && !f.bo)
return 1;
else if(!people[0] && f.bo)
return 1;
else
return 0;
}
else
return 0;
}
} int write(char str[])
{
if(strncmp(str, "divine.", 7) == 0)
return 3;
else if(strncmp(str, "human.", 6) == 0)
return 2;
else if(strncmp(str, "evil.", 5) == 0)
return 1;
else if(strncmp(str, "day.", 4) == 0)
return 5;
else if( strncmp(str, "night.", 6) == 0)
return 4;
else if( strncmp(str, "lying.", 6) ==0)
return -1;
} void read(say tem[])
{
char str[M];
int id; for(int i = 0; i < n; i++)
{
cin >> str;
tem[i].talk = str[0];
id = str[0] - 'A' + 1;
brith[id] = 1; cin >> str;
if(strcmp(str, "It") == 0)
tem[i].name = 'T';
else if(str[0] == 'I')
tem[i].name = tem[i].talk;
else
{
tem[i].name = str[0];
id = str[0] - 'A' + 1;
brith[id] = 1;
} cin >> str;
cin >> str;
if(strcmp(str, "not"))
{
tem[i].bo = 1;
tem[i].sex = write(str);
}
else
{
tem[i].bo = 0;
cin >> str;
tem[i].sex = write(str);
} // if(tem[i].sex == -1 && tem[i].talk == tem[i].name && tem[i].bo)
// FP = 1;
}
} int judge(say tem[])
{
for(int i = 0; i < n; i++)
{
int id = tem[i].talk - 'A' + 1;
if(people[id] == 3)
{
if(ture_say(tem[i]))
continue;
else
return 0;
}
else if(people[id] == 2)
{
int f = ture_say(tem[i]);
if( (people[0] && f) || (!people[0] && !f) )
continue;
else
return 0;
}
else if(people[id] == 1)
{
if(!ture_say(tem[i]))
continue;
else
return 0;
}
}
return 1;
} void build(int k, say tem[])
{
if(k < 6)
{
if(brith[k])
{
for(people[k] = 1; people[k] < 4; people[k]++)
build(k + 1, tem);
}
else
build(k + 1, tem);
}
else if(judge(tem))
{
// cout << k << endl;
if(ok >= 1)
thesome();
else
for(int i = 0; i < 6; i++)
now[i] = people[i];
ok++;
} } int main()
{
int t = 1;
while(cin >> n, n)
{
// Init.
memset(people, 0, sizeof(people));
memset(brith, 0, sizeof(brith));
ok = 0;
say tem[N];
// FP = 0;
memset(yes, 0,sizeof(yes)); // ReadZZg.
read(tem); cout << "Conversation #" << t++ << endl;
// if(FP)
// cout << "This is impossible." << endl;
// else
// {
for(people[0] = 0; people[0] < 2; people[0]++)
build(1, tem); if(ok == 0)
cout << "This is impossible." << endl;
else
{
//*
int oi = 0;
for(int i = 1; i < 6; i++)
{
if(!yes[i] && now[i])
{
oi++;
char c = 'A' + i - 1;
if(now[i] == 3)
cout << c << " is divine." << endl;
else if(now[i] == 2)
cout << c << " is human." << endl;
else if(now[i] == 1)
cout << c << " is evil." << endl;
}
} if(oi == 0 && yes[0])
cout << "No facts are deducible." << endl;
if(now[0] && !yes[0])
cout << "It is day." << endl;
else if(!yes[0])
cout << "It is night." << endl;
// }
}
cout << endl;
}
return 0;}

uva 592 Island of Logic (收索)的更多相关文章

  1. 20170712 SQL Server 日志文件收索

    -- 1 日志文件增长过快,未进行任务计划截断备份 造成文件过大199G 左右,而可用空间不足8% -- 2 日志备份之前,需要一次完整备份 再进行截断备份 出现可用空间99% 此时可以选择收索数据库 ...

  2. 剑指offer-第四章解决面试题思路(二叉收索树和双向链表)

    题目:输入一个二叉收索树,将二叉搜索树转换成排序的双向链表.要求不能创建节点,只能将链表中的指针进行改变. 将复杂的问题简单化:思路:二叉收索树,本身是一个排序结构,中序遍历二叉收索树就可以得到一组排 ...

  3. 【转载】快速收索并更新sid 方法

    利用Google的搜索功能,可以获得不少SAS各个版本的SID号,试过之后你会异常惊喜.1.打开谷歌: http://google.com.hk2.输入或复制这个段文字:"SID_heade ...

  4. Combox 实现百度收索框效果

    标题中所谓百度收缩框效果,就是在输入数据的时候,自动提示,来张图就明白了: 用Combox来实现这个功能只是需要设置三个A开头的属性就OK了:AutoCompleteSource.AutoComple ...

  5. Uva592 Island of Logic

      题意:神人鬼三个种族,神只说真话,鬼只说假话,人白天说真话,晚上说假话.根据对话内容区分种族和白天黑夜.  最多有A, B, C, D, E五个人 算法:枚举A, B, C, D, E的种族情况和 ...

  6. 企业常用的站内收索、QQ群、在线客服

    <div class="toplinks">            <form target="_blank">             ...

  7. bootstrapTable 应用小例(收索)

    <script src="/plugins/My97DatePicker/WdatePicker.js"></script> <!-- Content ...

  8. 自定义收索View

    1 .h文件 @interface SearchNavView : UIView @property (nonatomic, copy) void(^cancleBtnBlock)(void); @p ...

  9. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

随机推荐

  1. tarjan算法(割点/割边/点连通分量/边连通分量/强连通分量)

    tarjan算法是在dfs生成一颗dfs树的时候按照访问顺序的先后,为每个结点分配一个时间戳,然后再用low[u]表示结点能访问到的最小时间戳 以上的各种应用都是在此拓展而来的. 割点:如果一个图去掉 ...

  2. hdu3278Puzzle

    其实最终的结果无非是中间8个方块是相同的颜色,外面16个方块是另外两种颜色.那么其实可以把外面两种颜色看作是0,中间的颜色看做是1. 那么题目就变成了把那种颜色看做1,而其它两种颜色看做0,可以用最少 ...

  3. Android学习笔记(四十):Preference使用

    Preference从字面上看偏好,译为首选项. 一些配置数据,一些我们上次点击选择的内容.我们希望在下次应用调起的时候依旧有效,无须用户再一次进行配置或选择.Android提供preference这 ...

  4. Java实现字符全阵列阵列

    import org.junit.Test; public class AllSort { public void permutation(char[] buf, int start, int end ...

  5. 协同编辑多人word一个小技巧文件

    协同编辑多人word窍门 近期在工作中编写标书时因为不同内容分给了各个部门去制作.可是在汇总后遇到再次改动的问题.对方把改动后的部分文档发给我粘贴到标书中后,所有的格式所有都乱了.又一次整理格式.标题 ...

  6. SharePoint综合Excel数据与Excel Web Access Web部分

    SharePoint综合Excel数据与Excel Web Access Web部分 Excel Web Access Web零件SharePoint于Excel以电子形式提交数据. 1. 打开Exc ...

  7. 希尔排序java

    希尔排序简述 希尔排序是基于插入排序的以下两点性质而提出改进方法的: 插入排序在对几乎已经排好序的数据操作时,效率高,即可以达到线性排序的效率.(希尔排序先将部分数据进行排序,相当于已经部分排好序) ...

  8. Linux下PS命令详解 (转)

    要对系统中进程进行监测控制,查看状态,内存,CPU的使用情况,使用命令:/bin/ps (1)ps :是显示瞬间进程的状态,并不动态连续: (2)top:如果想对进程运行时间监控,应该用 top 命令 ...

  9. BeagleBone Black 板第三课:Debian7.5系统安装和远程控制BBB板

    BBB板第三课:Debian7.5系统安装和远程控制BBB板 由于BBB板系统是Debian 7.4.据说使用Debian系统能够实现非常多BBB板的无缝连接.能够更好的学习和控制BBB板,所以就决定 ...

  10. ehcache.xml设置(转)

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...