uva 592 Island of Logic

quartus 13.1常见报错解决方法 在使用quartus中会遇到很多由于安装或设置不规范造成的错误。我就目前我遇到的一些错误以及我的解决方法分享给大家,这个文章将会持续更新,如果读者有遇到软件中错误无法解决的问题,也欢迎在评论区留言。 一、编译出现lience错误 在对设计的电路编译时,系统在程序运行3秒内即结束并报错,大概意思为现有的证书不支持编译。这个常见问题源自破解不成功,这里读者很有可能犯的错误是在使用破解器的时候没有区分x86(即32-bit)和x64软件破解器对应的文件夹。 如图所示有两种破解器,分别对应32位和64位的软件,大部 阅读详情

题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=533


题目描述:


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 A, B, C, D, E. 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.







Reasoning made easy

To make things clearer, we will show the reasoning behind the third input example, where A says `` I am evil. ''. What can be deduced from this? Obviously A cannot be divine, since she would be lying, similarly A cannot be evil, since she would tell the truth. Therefore, A must be human, moreover, since she is lying, it must be night. So the correct output is as shown.

In the fourth input example, it is obvious that A is lying since her two statements are contradictory. So, B can be neither human nor evil, and consequently must be divine. B always tells the truth, thus A must be evil. Voil‘a!



Miguel A. Revilla 
1998-03-10




题意:

说一个叫逻辑岛的地方住着三种生物,神族  人族   和 虫族(对应于星际争霸。。。)  这三个种族有以下特点:

1.神族只能说真话

2.虫族只能说假话

3.人族 在白天 只能说真话  在晚上只能说假话

先给出一系列对话  让你做出相应的判断。


题解:

注意到仅有ABCDE五个生物的判断,所以直接穷举出ABCDE的全部种族可能性 然后再用每一种穷举出的可能去验证一系列对话的真实性。

在验证过程中 实际上就是求所有可能出现的矛盾。

然后我们用一个答案数组来存储所有情况中合理的情况。

在验证的过程中,若检测出矛盾 则这种情况是不被加入答案数组的,若是合理的则加入。当所有情况遍历完后,整理答案数组(合并求最大交集)。

若整理后的答案数组中  仅有一个答案 则输出具体的答案结果。

  若有多个答案 则是不能推出任何确切的答案 即No facts are deducible。

  若有零个答案 自然就是impossible了。


所涉及的struct结构  info。

将input中的叙述转化为info的结构

info结构有{叙述者,被叙述者,肯定语气or否定语气,叙述内容/叙述宾语};

算法伪代码:
procedure
{

    switch(A)//A is divine or evil or human
    {
        swtich(B)
        {
            ......
            {
                swtich(E)
                {
                    swtich(weather)//weather is day or night
                    {
                        if(check()==true)//这一种枚举情况是合理的,那么加入答案数组
                        {
                            AddAns();
                        }
                    }
                }
            }
        }
    }
    ArrangeAns();//整理答案,包括去除重复答案,空/无意义 答案,合并等价答案 //等等,求答案的最大交集 若不为空 将答案集数量置1 并且内容值即为最大交集的内容
    if(count==1)
    {
        OutputAns();
    }
    else if(count==0)
    {
        impossible;
    }
    else
    {
        no facts....
    }
}


check 的矛盾检测:

for:遍历n条叙述
{
    按叙述分类讨论:I am 类  ,X is 类 ,It is类
    {
        case I am:
        {
            按叙述宾语展开:
            {
                按叙述者身份展开讨论:
                {
                    按肯定和否定展开
                    {
                        按被叙述者展开:
                        {
                            讨论存在的矛盾 若矛盾return(false);
                        }
                    }
                }
            }
        }
        ..............//后面的类型讨论与上述大同小异。
    }
}


代码:

/*
uva:592 - Island of Logic
	
evil cannot tell the truth that is he always is lying

if lying then it must not be truth and it must be false

I want to use brute force to deal with it

5 persons A B C D E

for every one that can be three states: divine  evil   human



then we could know who lying according to this and who tell the truth
and that we will check the suppose whether it is correct


think about that the case of the "conflict" occurs is what

1.divine tell not truth or divine lying
2.evil tell the truth
3.human say truth in night and say lying in day

we think about the ans again
1.success means the valid answer is unique
2.impossible means the all possible answer is conflict
3.undeducible means there are more than two answers is success

so we should save every deducible result
and in the end we would analysis these result


I don't know the sample 2
how dose it is maked???

now it's so upset for me that the code is WA for the test data of discuss#############


I can not pass  the test data # 7  #8  #15 at present in 2013 4.15
I have passed all the given test data in 2013 4.16 but still get WA in uva OJ
	take the standard program and i will make the random test data
*/
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
using namespace std;

int Inhabitants[5]={0};//means A B C D E;
int OldInhabitants[5]={0};
//0 means no this person
//1 means divine
//2 means evil
//3 means human
//4 means this person is exist but can not comfirm his ID
int Weathers=0;//0->did not know the weather 1->day 2->night
int OldWeathers=0;

int Result[243][5]={0};//3*3*3*3*3  Resuilt[i][0]==-1 is invalid
bool IsValid[243]={false};
int ResultWea[243]={0};
int ValidCnt=0;
int cnt=0;//count the number of the results
int Strongs[243]={0};//the value of strong the more divine human or evil the bigger the value is
int MaxStrongs=0;//save the max strongs
int Refer[5]={0};//0 is not refer  1 is refer

bool IsConflict=false;

/*save the input info and construct it*/
typedef struct Info
{
	char Sayer;
	char Object[5];//A B C D E I(ABCDE) it
	bool IsOrNot;//true means is  false means is not
	char Content[20+5];
	Info()
	{
		Sayer='\0';
		memset(Object,'\0',sizeof(Object));
		IsOrNot=false;
		memset(Content,'\0',sizeof(Content));
	}
}Info;//note that sort the info array

int n=0;
char GStr[20+5]={'\0'};

/*make a proper struction*/
int MakeStruction(char GStr[],Info Information[],int i)
{
	Information[i].Sayer=GStr[0];
	if(GStr[3]=='I')
	{
		if(GStr[4]=='t')
		{
			strcpy(Information[i].Object,"It");
		}
		else
		{
			Information[i].Object[0]=GStr[0];
			Information[i].Object[1]='\0';
		}
	}
	else
	{
		Information[i].Object[0]=GStr[3];
		Information[i].Object[1]='\0';
	}
	if(strstr(GStr,"not")==NULL)
	{
		Information[i].IsOrNot=true;
	}
	else
	{
		Information[i].IsOrNot=false;
	}
	strcpy(Information[i].Content,strrchr(GStr,' ')+1);//divine lying etc.
	return(0);
}

/*check the Inhabitants whether is valid,n is the end of the check index 0~n*/
bool Check(Info Information[],int end)
{
	int i=0,j=0;
	for(i=0;i<=n-1;i++)//scan the info
	{
		bool IsOrNot=Information[i].IsOrNot;
		//I am ...
		if(Information[i].Object[0]==Information[i].Sayer)
		{
			switch(Information[i].Content[0])
			{
				case 'l'://lying
				//find this identity
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)//divine did not lying
				{
					return(false);
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==1)//human did not lying in day
				{
					return(false);
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==2)//human did not lying in day
				{
					return(false);
				}
				//it's uncomfirmed
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)//evil did not tell the truth he did not say he is lying
				{
					return(false);
				}
				if(IsOrNot&&Weathers==0&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)//divine did not lying
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==2)//human did not lying in day
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==0)
				{
					return(false);
				}
				break;
				case 'd'://divine,two ways thinking,who can not say this words that is to say it's conflict
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==1)
				{
					return(false);
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==0)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==2)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==0)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)
				{
					return(false);
				}
				break;
				case 'e'://evil
				if(IsOrNot&&(Inhabitants[Information[i].Sayer-'A']==2||Inhabitants[Information[i].Sayer-'A']==1))//evil did not tell the truth
				{
					return(false);
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==1)
				{
					return(false);
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==0)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==2)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3&&Weathers==0)
				{
					return(false);
				}
				//#####################Inhabitants[Information[i].Sayer-'A']==3&&Weathers==0 is also false
				break;
				case 'h'://human
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)
				{
					return(false);
				}
				if(IsOrNot&&Weathers==2&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					return(false);
				}
				if(IsOrNot&&Weathers==0&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					return(false);
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)
				{
					return(false);
				}
				if(!IsOrNot&&Weathers==1&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					return(false);
				}
				if(!IsOrNot&&Weathers==0&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					return(false);
				}
				//human always match to the weather  that is to say  if there are human it must we konw the weather
				//the comfirm of human need the comfirm fo weather
				//if(Weathers==0)
//				{
//					return(false);
//				}
				break;
				default:
				break;
			}
		}
		//X is ...
		else if(Information[i].Object[0]!=Information[i].Sayer&&Information[i].Object[1]!='t')
		{
			switch(Information[i].Content[0])
			{
				case 'l'://lying
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)//divine say the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']==1)//divine did not lying
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==1)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
					//how about weather is 0??
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)//evil say not the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']==2)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==2)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)//human the day and night
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==1)//divine did not lying
						{
							return(false);
						}
						if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==1)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==2)
						{
							return(false);
						}
						if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==2)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)//divine
				{
					if(Inhabitants[Information[i].Object[0]-'A']==2)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==2)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)
				{
					if(Inhabitants[Information[i].Object[0]-'A']==1)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==1)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==2)
						{
							return(false);
						}
						if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==2)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==1)
						{
							return(false);
						}
						if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==1)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				break;
				case 'd'://divine
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)//divine say the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']!=1)
					{
						return(false);
					}
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)//evil say not the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']==1)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)//human the day and night
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']!=1)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==1)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)
				{
					if(Inhabitants[Information[i].Object[0]-'A']==1)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)
				{
					if(Inhabitants[Information[i].Object[0]-'A']!=1)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==1)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
						if(Inhabitants[Information[i].Object[0]-'A']!=1)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				break;
				case 'e'://evil
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)//divine say the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']!=2)
					{
						return(false);
					}
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)//evil say not the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']==2)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)//human the day and night
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']!=2)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==2)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)
				{
					if(Inhabitants[Information[i].Object[0]-'A']==2)
					{
						return(false);
					}
					if(Inhabitants[Information[i].Object[0]-'A']==3&&Weathers==0)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)
				{
					if(Inhabitants[Information[i].Object[0]-'A']!=2)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==2)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
						if(Inhabitants[Information[i].Object[0]-'A']!=2)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				break;
				case 'h'://human
				//uncomfirmed
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)//divine say the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']!=3)
					{
						return(false);
					}
				}//we forgot the is and is not..................................
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)//evil say not the truth
				{
					if(Inhabitants[Information[i].Object[0]-'A']==3)
					{
						return(false);
					}
				}
				if(IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)//human the day and night
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']!=3)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==3)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==1)
				{
					if(Inhabitants[Information[i].Object[0]-'A']==3)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==2)
				{
					if(Inhabitants[Information[i].Object[0]-'A']!=3)
					{
						return(false);
					}
				}
				if(!IsOrNot&&Inhabitants[Information[i].Sayer-'A']==3)
				{
					if(Weathers==1)
					{
						if(Inhabitants[Information[i].Object[0]-'A']==3)
						{
							return(false);
						}
					}
					else if(Weathers==2)
					{
	  					if(Inhabitants[Information[i].Object[0]-'A']!=3)
						{
							return(false);
						}
					}
					else
					{
						return(false);
					}
				}
				break;
				default:
				break;
			}
		}
		//It is ...  no isornot bool
		else//if there are two weathers which one we should select to our standard weathers??
		{//sorry that we have burte forced the standard weathers
			int day=(Information[i].Content[0]=='d')?1:2;
			if(Weathers>0)
			{
				if(Inhabitants[Information[i].Sayer-'A']==1)
				{
					if(Weathers!=day)
					{
						return(false);
					}
				}
				if(Inhabitants[Information[i].Sayer-'A']==2)
				{
					if(Weathers==day)
					{
						return(false);
					}
				}
				if(Inhabitants[Information[i].Sayer-'A']==3)
				{
					if(Weathers==1)
					{
						if(Weathers!=day)
						{
							return(false);
						}
					}
					else//2
					{
						if(Weathers==day)
						{
							return(false);
						}
					}
				}
			}
		}
	}
	return(true);
}

/*result[cnt++]=inhabitants*/
int AddResult()
{
	int i=0;
	int strongs=0;
	for(i=0;i<=5-1;i++)
	{
		Result[cnt][i]=Inhabitants[i];
		if(Inhabitants[i]!=4&&Inhabitants[i]!=0)
		{
			strongs++;
		}
	}
	ResultWea[cnt]=Weathers;
	Strongs[cnt]=strongs;
	IsValid[cnt]=true;
	if(MaxStrongs<strongs)
	{
		MaxStrongs=strongs;
	}
	cnt++;
	return(0);
}

/*output the onlu one successful case*/
int OutputTruth()
{
	int i=0,j=0;
	for(i=0;i<=cnt-1;i++)
	{
		if(IsValid[i])
		{
			for(j=0;j<=5-1;j++)
			{
				switch(Result[i][j])
				{
					case 1://divine
					printf("%c is divine.\n",j+'A');
					break;
					case 2://evil
					printf("%c is evil.\n",j+'A');
					break;
					case 3://human
					printf("%c is human.\n",j+'A');
					break;
					default:
					break;
				}
			}
			if(ResultWea[i]>0)
			{
				if(ResultWea[i]==1)
				{
					printf("It is day.\n");
				}
				else
				{
					printf("It is night.\n");
				}
			}
		}
	}
	return(0);
}

/*compare for the sort*/
bool cmp(Info A,Info B)
{
	return(A.Sayer<B.Sayer);
}

/*compare the array*/
bool IsEqual(int a[],int b[],int M)
{
	int i=0;
	for(i=0;i<=M-1;i++)
	{
		if(a[i]!=b[i])
		{
			return(false);
		}
	}
	if(OldWeathers!=Weathers)
	{
		return(false);
	}
	return(true);
}

/*copy the value sets*/
int HabCpy(int a[],int b[],int M)
{
	int i=0;
	for(i=0;i<=M-1;i++)
	{
		a[i]=b[i];
	}
	return(0);
}

/*check the repeat element*/
bool IsRepeat()
{
	int i=0;
	for(i=0;i<=cnt-1;i++)
	{
		if(IsValid[i]==false)
		{
			continue;
		}
		//Weathers==ResultWea[i]&&
		if(Inhabitants[0]==Result[i][0]&&Inhabitants[1]==Result[i][1]&&Inhabitants[2]==Result[i][2]&&Inhabitants[3]==Result[i][3]&&Inhabitants[4]==Result[i][4])
		{
			if(Weathers==ResultWea[i])
			return(true);
		}
	}
	return(false);
}

/*is all 4 them we could not add*/
bool IsAllNotKnow()
{
	int i=0;
	for(i=0;i<=5-1;i++)
	{
		if(Inhabitants[i]==4||Inhabitants[i]==0)
		{
			;
		}
		else
		{
			return(false);
		}
	}
	
	//weathers??
	return(true);
}

/*judge this type , onliy one bit is diffrent besides it's 1 2 3 struction*/
bool IsFourType(int &FourPos,int Prev2,int Prev1,int Now)
{
	int j=0;
	int diffCnt=0;
	int diffPos=0;
	for(j=0;j<=5-1;j++)
	{
		if(Result[Prev2][j]==Result[Prev1][j]&&Result[Prev1][j]==Result[Now][j])
		{
			
		}
		else
		{
			diffCnt++;
			diffPos=j;
		}
	}
	if(diffCnt==1&&ResultWea[Prev2]==ResultWea[Prev1]&&ResultWea[Prev1]==ResultWea[Now]&&Result[Prev2][diffPos]==1&&Result[Prev1][diffPos]==2&&Result[Now][diffPos]==3)
	{
		FourPos=diffPos;
		return(true);
	}
	else
	{
		return(false);
	}
}

/*weather 1  weather 2->0*/
bool IsWeatherType(int now,int prev)
{
	if(Result[now][0]==Result[prev][0]&&Result[now][1]==Result[prev][1]&&Result[now][2]==Result[prev][2]&&Result[now][3]==Result[prev][3]&&Result[now][4]==Result[prev][4])
	{
		if(ResultWea[now]+ResultWea[prev]==3)//1 2 or 2 1
		{
			return(true);
		}
	}
	return(false);
}

/*arrange the result clean the lower truth  and 1 2 3 => 4*/
int ArrangeResult()
{
	//find the max strong
	int i=0,j=0;
	//note that inconsecutive
	int Prev2=-1,Prev1=-1,Now=-1;
	int Count1=0,Count2=0;
	int prev=-1,now=0;//the array is inconsecutive
	Count1=1;
	Count2=1;
	while(Count1||Count2)
	{
		Count1=0;
		Prev2=-1;
		Prev1=-1;
		Now=-1;
		for(i=0;i<=cnt-1;i++)
		{
			if(IsValid[i])
			{
				Now=i;
				if(Strongs[i]<MaxStrongs)
				{
					IsValid[i]=false;
					ValidCnt--;
				}
				else
				{
					if(Now>=0&&Prev1>=0&&Prev2>=0)//is 1 2 3 =>4 type
					{
						int FourPos=0;
						if(IsFourType(FourPos,Prev2,Prev1,Now))
						{
							IsValid[i-1]=false;
							ValidCnt--;
							IsValid[i-2]=false;
							ValidCnt--;
							IsValid[i]=true;
							Result[i][FourPos]=4;
							Count1++;//if there are no fourtypes the Count is 0
						}
					}
				}
				if(IsValid[Now])
				{
					Prev2=Prev1;
					Prev1=Now;
				}
			}
		}
		Count2=0;
		prev=-1;
		now=0;
		for(i=0;i<=cnt-1;i++)
		{
			if(IsValid[i])//conbine the weathers
			{
				if(prev>=0)
				{
					now=i;
					if(IsWeatherType(now,prev))
					{
						IsValid[prev]=false;
						ValidCnt--;
						IsValid[now]=true;
						ResultWea[now]=0;
						Count2++;
					}
				}
				prev=now;
			}
		}
	}
	//all 0 or all 4  is invalid
	for(i=0;i<=cnt-1;i++)
	{
		if(IsValid[i])
		{
			int ValueCnt=0;
			int j=0;
			for(j=0;j<=5-1;j++)
			{
				if(Result[i][j]!=4&&Result[i][j]!=0)
				{
					ValueCnt++;
				}
			}
			if(ValueCnt==0)
			{
				IsValid[i]=false;
				ValidCnt--;
			}
		}
	}
	
	int Conbine[5]={0};
	int ConWea=0;
	//get the bigist U such as 21202!1 U 23202!1=20202!1
	//printf("####%d####\n",ValidCnt);
 	now=-1;
	prev=-1;
	for(j=0;j<=5-1;j++)
	{
		now=-1;
		prev=-1;
		for(i=0;i<=cnt-1;i++)
		{
			if(IsValid[i])
			{
				now=i;
				if(prev>=0)
				{
					if(Result[now][j]==Result[prev][j])
					{
						Conbine[j]=Result[now][j];
					}
					else
					{
						Conbine[j]=0;
						break;
					}
				}
				prev=now;
			}
		}
	}
	//weather
	now=-1;
	prev=-1;
	for(i=0;i<=cnt-1;i++)
	{
		if(IsValid[i])
		{
			now=i;
			if(prev>=0)
			{
				if(ResultWea[now]==ResultWea[prev])
				{
					ConWea=ResultWea[now];
				}
				else
				{
					ConWea=0;
					break;
				}
			}
			prev=now;
		}
	}
	//check the Conbine is or is not valid
	int ValueCnt=0;
	for(j=0;j<=5-1;j++)
	{
		if(Conbine[j]!=4&&Conbine[j]!=0)
		{
			ValueCnt++;
		}
	}
	if(ConWea>0)
	{
		ValueCnt++;
	}
	if(ValueCnt>0)
	{
		ValidCnt=1;
		cnt=1;
		Result[0][0]=Conbine[0];
		Result[0][1]=Conbine[1];
		Result[0][2]=Conbine[2];
		Result[0][3]=Conbine[3];
		Result[0][4]=Conbine[4];
		ResultWea[0]=ConWea;
		IsValid[0]=true;
	}
	return(0);
}

/*for test*/
int test()
{
	return(0);
}
int cases=0;

/*main process*/
int MainProc()
{
	while(scanf("%d",&n)!=EOF&&n>0)
	{
		getchar();//because of gets()  , we eat the \n
		int i=0;
		Info Information[n];
		memset(Inhabitants,0,sizeof(Inhabitants));
		memset(OldInhabitants,0,sizeof(OldInhabitants));
		memset(Strongs,0,sizeof(Strongs));
		MaxStrongs=0;
		memset(IsValid,false,sizeof(IsValid));
		IsConflict=false;
		cnt=0;
		cases++;
		printf("Conversation #%d\n",cases);
		OldWeathers=-1;
		for(i=0;i<=n-1;i++)//get the data and make it data struction from the input
		{
			gets(GStr);
			MakeStruction(GStr,Information,i);
			Inhabitants[GStr[0]-'A']=4;//flag the appeared inhabitants,this is refer operation
			if(GStr[3]>='A'&&GStr[3]<='E')
			{
				Inhabitants[GStr[3]-'A']=4;
			}
		}
		//sort the information
		sort(Information,Information+n,cmp);
		//for(i=0;i<=5-1;i++)
//		{
//			if(Inhabitants[i]==4)
//			{
//				int j=0;
//				for(j=1;j<=3;j++)
//				{
//					Inhabitants[i]=j;
//				}
//			}
//		}//it will set up the threes tree to travels
		int j0,j1,j2,j3,j4;
		for(j0=1;j0<=3;j0++)
		{
			if(Inhabitants[0]>0)//if the info refer to the person then we can brute force it
			{
				Inhabitants[0]=j0;
			}
			//if(Check(0)==false)//check the suppose wether have the conflict
//			{
//				Inhabitants[0]=4;//it is still uncomfirmed
//				continue;
//			}//check the middle role is a little difficult for the design of the check function
			for(j1=1;j1<=3;j1++)
			{
				if(Inhabitants[1]>0)
				{
					Inhabitants[1]=j1;
				}
				//if(Check(1)==false)
//				{
//					Inhabitants[1]=4;//it is still uncomfirmed
//					IsConflict=true;
//					continue;
//				}
				for(j2=1;j2<=3;j2++)
				{
					if(Inhabitants[2]>0)
					{
						Inhabitants[2]=j2;
					}
					//if(Check(2)==false)
//					{
//						Inhabitants[2]=4;//it is still uncomfirmed
//						IsConflict=true;
//						continue;
//					}
					for(j3=1;j3<=3;j3++)
					{
						if(Inhabitants[3]>0)
						{
							Inhabitants[3]=j3;
						}
						//if(Check(3)==false)
//						{
//							Inhabitants[3]=4;//it is still uncomfirmed
//							IsConflict=true;
//							continue;
//						}
						for(j4=1;j4<=3;j4++)
						{
							if(Inhabitants[4]>0)
							{
								Inhabitants[4]=j4;
							}
							for(Weathers=1;Weathers<=2;Weathers++)//weather brute force
							{
								//for debug
								if(j0==1&&j1==1&&j2==3&&j3==2&&j4==1)
								{
									j0=1;
								}
								//many redundancy checked
								if(!IsEqual(Inhabitants,OldInhabitants,5)&&!IsRepeat())
								{
									if(Check(Information,4)==false)
									{
										IsConflict=true;
										HabCpy(OldInhabitants,Inhabitants,5);
										OldWeathers=Weathers;
										continue;
									}
									else//it's successfully true
									{
										if(!IsAllNotKnow())
										AddResult();//result[cnt++]=inhabitants
										HabCpy(OldInhabitants,Inhabitants,5);
										OldWeathers=Weathers;
										if(Weathers==0)
										{
											break;//the weather is unnecessary
										}
									}
								}
							}
						}
					}
				}
			}
		}
		//display the Result array
		//printf("****************************\n");
//		printf("%d.\n",cnt);
//		for(i=0;i<=cnt-1;i++)
//		{
//			if(IsValid[i])
//			{
//				printf("   #%d\n",i);
//				int j=0;
//				for(j=0;j<=5-1;j++)
//				{
//					printf("%d",Result[i][j]);
//				}
//				printf("!%d",ResultWea[i]);
//				printf("\n");
//			}
//		}
		//maybe impossible or undeducible or success
		ValidCnt=cnt;
		//arrange the result array  1 2 3->4  inhabitants  and 1 2 ->0 weather
		ArrangeResult();
		if(ValidCnt==0)//impossible
		{
			printf("This is impossible.\n");
		}
		else if(ValidCnt==1)//success
		{
			OutputTruth();//judge the weather
		}
		else//undeducble
		{
			printf("No facts are deducible.\n");
			//for test
			//printf("****************************\n");
//			int i=0;
//			for(i=0;i<=cnt-1;i++)
//			{
//				if(IsValid[i])
//				{
//					printf("   #%d\n",i);
//					int j=0;
//					for(j=0;j<=5-1;j++)
//					{
//						printf("%d",Result[i][j]);
//					}
//					printf("!%d",ResultWea[i]);
//					printf("\n");
//				}
//			}
		}
		printf("\n");
	}
	return(0);
}

int main()
{
	MainProc();
	return(0);
}








AutoSAR系列讲解 - 前言 博主xyfx是一名汽车行业的嵌入式软件工程师,本职工作是同步电机的驱动控制(主要做FOC的,这个大家要是有兴趣,以后可以单独开一个专栏来讲解一下),由于做控制器的时候需要用到AutoSAR,所以特意的去学习了相关知识,同时博主自己也在同步提高中,有写的不合理的地方也请大家指正。我准备对AutoSAR开设两个大的方面来讲解,一是AutoSAR的入门篇,二是AutoSAR的实践篇,分别讲述AutoSAR的理论基础和工具的使用。 阅读详情

相关推荐

Centos7搭建OpenStack+创建iaas云主机

主要说明在控制节点和计算节点上,通过脚本的形式,安装OpenStack的iaas安装步骤和创建可运行的云主机。提供实施简单、可大规模扩展、丰富、标准统一的云计算管理平台。

weixin_48218106的博客 1万+

UVa 592 Island of Logic (有趣的枚举题)

592 - Island of Logic Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=107&amp;page=show_problem&amp;problem=533 The Island of Log...

844604778 258

《计算机网络》复试问答题总结

DNS 是一个联机分布式数据库系统,负责主机名和 IP 地址之间的转换,需要进行域名查询的机器主动发起域名解析请求,域名服务器则随时准备做出响应。域名服务器的数据库中存放着它所管辖范围的主机名和 IP 地址之间的映射表,域名服务器之间又可以相互联络和协作,以便分布在 Internet 各个域名服务器数据库中的域名都能被有效地搜索,从而实现主机名与 IP 地址的映射。为了提高解析效率,使用了域名缓存技术。在服务器、主机中设置一个专用的内存缓冲区。服务器用来存放近期解析过的域名及其对应的 IP 地址的映射。

weixin_45971154的博客 2034

UVA 592 逻辑之岛(暴力枚举)

UVA 592 逻辑之岛

Remilia's 1946

黏菌算法(Slime Mould Algorithm,SMA)

这是一篇关于黏菌算法的总结博客,包含算法思想,算法步骤,求函数最值(Python实现),算法改进等,持续更新ing

weixin_46838605的博客 1万+

刷题单向链表

实现一个数据结构,维护一张表(最初只有一个元素 11)。接下来 qq 行,每行表示一次操作,操作具体间题目描述。a[i] 里面放的是下一个元素,为0代表链表结束。如单链表1->4 -> 2->3->0用数组表示是。对于每个操作 2,输出一个数字,用换行隔开。第一行一个整数 qq 表示操作次数。

power的专栏 1718

UVA592字符串推断题加暴力假设搜索

这题稍微有些复杂,当时想了很久没敢下手敲,主要还是代码能力不够,有了基本的思想不敢敲, 而这道题实际上就是暴力搜索,因为只有五个人加上天气一共六个,直接假设就行了。 这里用一个birth数组存储对话过程中曾经出现的人物。然后结果肯定是通过出现过的人物然后假设就行了。 同时注意如果搜索的所有情况均不可行,说明对话有错误,即是第一种情况。此外有一种情况成立并不能说明什么, 只有在所有情况下都成

ONE_PIECE的专栏 498

S-function入门及案例详解(1)——S-function基础介绍及基本案例

本专题将用三篇文章对S-function进行介绍及其案例详解。欢迎关注~ 目录一、S-Function简介二、详解sfuntmpl函数2.1 sfuntmpl函数介绍2.2 mdlInitializeSizes函数2.3 mdlDerivatives函数2.4 mdlUpdate函数2.5 mdlOutputs函数2.6 mdlGetTimeOfNextVarHit函数2.7 mdlTerminate函数三、案例1——对波形的幅值进行放大3.1 案例分析3.2 案例详解3.3 输出波形四、案例2——对波形的

Wendy的博客 7万+

UVA 592 逻辑之岛

I/O 操作太麻烦,转一篇 #include #define DIVINE 0 #define EVIL 1 #define HUMAN 2 #define DAY 0 #define NIGHT 1 #define MAXPERSONS 5 #define STATENUM 3*3*3*3*3*2 char state[STATENU

cfzjxz的专栏 1115

从零开始的计网学习——物理层

计算机网络对于IT人不论是就业还是升学都是核心的一门课程,一起从零开始,学习计算机网络!

Nimrod__的博客 2万+

三相五柱式消弧线圈自动测控装置设计与实现

本文设计了一种基于STM32的三相五柱式消弧线圈自动测控装置。该装置采用信号注入法检测系统对地电容电流,通过PID自适应算法调节消弧线圈电感值,实现单相接地故障时的快速补偿。硬件系统包含信号采集、注入、控制执行等模块,软件采用Goertzel算法提取特征频率信号,结合增量式PID实现精确控制。实验结果表明,装置电容检测误差小于2%,调谐响应时间小于50ms,满足配电网对消弧线圈自动调谐的技术要求。

AI的内部世界的博客 241

UVA 592 Island of Logic

这道题目和 UVA 131有点像 都是把可能的结果列出来,然后去硬搜 我自己也是没有A,逻辑不好的人做这个很吃力 下面的代码是别人那里拿过来的,看的我头都大了 哈哈哈哈哈 #include #include using namespace std; #define N 55 #define M 10 int people[M]; int brith[M]; int n; int

再见孙悟空 473

YOLO系列算法改进 | 自研篇 | C3k2融合Circulant Attention注意力模块 | 给局部特征提取器装上了全局动态卷积核,兼顾效率、精度与泛化能力!| AAAI 2026

YOLO系列算法改进 | 自研篇 | C3k2融合Circulant Attention注意力模块 | 给局部特征提取器装上了全局动态卷积核,兼顾效率、精度与泛化能力!| AAAI 2026 (以YOLO26最新目标检测模型为基础,融合C3k2_Circulant创新模块改进Backbone)

2502_91881744的博客 245

UVa 592 Island of Logic

题目要求根据居民的话语推断其身份(神、人、恶魔)和昼夜状态。神总是说真话,恶魔总是说谎,人在白天说真话、晚上说谎。输入包含多组对话,每组包含若干语句。需判断是否存在一致的解,若无解则输出不可能;若有解则输出可确定的事实。解法采用枚举所有可能的身份和昼夜组合(共486种),验证每种组合是否与所有语句一致,最后统计共同结论。代码通过回溯法实现枚举,并针对不同语句类型进行逻辑验证。

寂静山林 182

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

UVA 592 - Island of Logic

这种题,说难吧不难,但是就是不好做,因为太麻烦,比较练代码能力。 解法比较简单,就是枚举所有可能的情况,挨个带进去检查就是了。但是实现起来就略麻烦了……纯练代码能力了吧。

_____ 633

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

UVa 592 - Island of Logic

/* 思路:枚举所有情况。 this is impossible. 所以情况都不满足条件。 No facts are deducible. 有满足条件的情况,但是情况之间没有交集,也就是说原条件不能推导出任何结论来。 fact: 满足条件的情况之间的交集。 */ #include #include #include using namespace std;

cugfjp的专栏 840

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

uva 592 Island of Logic (搜索)

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

不慌不忙、不急不躁 1955

uva592 - Island of Logic

暴力枚举,最多是3的5次方*2.比较麻烦,写了一晚上,调了一上午。 #include #include #include #include #include #include #define MARK -2147483647 using namespace std; char say[55][100]; int n;int isimpo;int renzhong[]={1

飞鸟的专栏 639

Uva592 Island of Logic

  题意:神人鬼三个种族,神只说真话,鬼只说假话,人白天说真话,晚上说假话。根据对话内容区分种族和白天黑夜。  最多有A, B, C, D, E五个人 算法:枚举A, B, C, D, E的种族情况和白天黑夜的情况。每个人有可能是神人鬼,所以用两个bit表示,白天黑夜用1个bit表示。一共需要11 bits.   #include&lt;iostream&gt; #include&...

weixin_33805992的博客 180

[暴力搜索]Island of Logic UVA592

暴力搜索的一道题目。

九问的烦恼 1196

POJ1478 HDU1470 ZOJ1252 UVA592 UVALive5625 Island of Logic【暴力】

Island of Logic Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 632 Accepted: 202 Description The Island of Logic has three kinds of inhabitants: divine beings that always tell the truth,...

海岛Blog 723

uva 592 Island of Logic (收索)

    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 hum...

weixin_33785108的博客 107
上一篇: hdu 1052 Tian Ji -- The Horse Racing
下一篇: Milk hdu 1070
hackerwin7
博客等级 码龄14年 115粉丝 144原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值