uva 592 Island of Logic

矩阵束(Matrix Pencil)入门:从通信系统到控制理论,它为何是建模利器? 本文深入探讨矩阵束(Matrix Pencil)在通信系统与控制理论中的关键作用,揭示其作为复杂系统建模利器的独特价值。从MIMO系统的多径干扰分析到电力系统稳定性判据,矩阵束通过`A-λB`方程求解提供精准建模方案,显著提升5G通信和工业控制等领域的性能表现。 阅读详情

题目地址: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);
}








【人工智能】提示词工程:让大模型精准响应的核心技术,提示词的基础框架 以及 常见提示词框架及场景 编写提示词的基础原则包括:简单、明确、详细,提示词拥有零样本提示、少样本提示、分配角色、提示写作风格、限定输出格式等技巧。 阅读详情

相关推荐

云服务器安装ros教程

要在 CentOS 7 系统上安装 RouterOS,您需要将 RouterOS 安装为虚拟机或直接安装到物理硬盘上。这里提供的是将 RouterOS 安装到物理硬盘上的步骤,这将完全替换现有的 CentOS 7 系统。请确保您已经备份了所有重要数据。

qq_37662563的博客 2145

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

用友U8自定义按钮开发:从基础配置到实战业务集成

本文详细介绍了用友U8自定义按钮开发的完整流程,从基础配置到实战业务集成。通过实际案例演示如何在U8系统中添加和替换功能按钮,包括数据库配置、SQL脚本编写和VB组件开发等关键技术点,帮助企业用户实现业务场景的深度定制。

weixin_29698641的博客 256

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

UVA 592 逻辑之岛

Remilia's 1945

【38】OpenCV C++实战篇——基于多项式插值的亚像素边缘定位算法

亚像素边缘定位算法实现 本文介绍了一种基于多项式插值的亚像素边缘定位算法,用于提高图像边缘检测的精度。文章首先分析了传统像素级边缘检测方法(如Canny、Sobel)的局限性,指出其在测量应用中的精度不足问题。 算法核心 梯度计算:使用8个方向模板进行卷积运算生成梯度图像 亚像素定位:采用多项式插值方法改进边缘定位精度 实现步骤: 生成8个方向的卷积模板(0°、45°、90°等) 利用filter2D函数计算各方向梯度 通过归一化处理显示梯度图像 代码特点 提供完整的C++实现代码 包含模板生成、梯度计算和

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 1099

【人工智能】Open WebUI 安装指南 ( 基于Docker下载和使用Open WebUI 、通过本地运行项目源码进行搭建Open WebUI)

Open WebUI 是一个可扩展、功能丰富且用户友好的自托管 WebUI,旨在完全离线操作。它支持各种 LLM 运行程序,包括 Ollama 和 OpenAI 兼容的 API。社区:https://openwebui.com/

奶爸的编程之路,也就一周冷个三天 2万+

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

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

ONE_PIECE的专栏 498

【推荐100个unity插件之27】推荐5种办法实现unity人物布料系统 衣服裙子飘动 头发飘动 胸部抖动 骨骼模拟 配件摆动 尾巴摆动 —— 主要是Magica Cloth 2插件

要实现Unity中的人物布料系统并使其具备动态效果,可以探索多种技术方法。这些方法不仅可以使衣服、裙子、头发等元素自然飘动,还可以实现胸部抖动、骨骼模拟、配件摆动和尾巴摆动等细致效果。本文将深入探讨五种实现这些动态效果的技术方案,从基础的物理模拟到高级的动画控制,帮助你打造逼真的人物表现。本文主要探究Magica Cloth 2的使用,因为我想探究最好的实现方法,而不是探究最多的实现方法。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 6305

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

Office 365中的Assigned Access详细功能介绍

本文系统介绍了Office365中AssignedAccess功能的应用与管理。作为Windows系统的重要安全特性,AssignedAccess可将设备锁定为单应用模式,有效防范未授权访问。文章详细阐述了其核心功能、技术架构及配置方法,包括UWP/Win32应用支持、多用户配置、与AzureAD集成等。通过MicrosoftEndpointManager可实现批量部署和远程监控,适用于公共终端、零售设备等场景。该功能为企业数字化转型提供了安全、可控的终端管理方案,在保障数据安全的同时优化用户体验。

xueyunshengling的博客 227

windows11下pycharm怎么完全卸载?完整卸载pycharm编辑器的教程

在卸载pycharm时都有遇到卸载不干净不完全的问题,那么具体怎样做才能完全卸载pycharm呢?退出所有的操作,重新启动电脑,会发现相关的软件已经被删除了。步骤1:卸载软件并删除安装目录。步骤2:删除相关的注册表。

拥抱具身智能,昇腾Ascend C 1万+

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

再见孙悟空 472

Python之afdx包语法、参数和实际应用案例

Python 的 afdx 包是针对 AFDX 协议的轻量级开发工具,专注于 AFDX 数据帧的解析、构造、发送/接收、协议合规性校验等核心能力,广泛应用于航空电子设备测试、仿真、数据监控等场景。

王国平的博客 984

UVa 592 Island of Logic

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

寂静山林 182

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

UVA 592 - Island of Logic

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

_____ 629

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

UVa 592 - Island of Logic

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

cugfjp的专栏 840

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

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

飞鸟的专栏 638

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、付费专栏及课程。

余额充值