爱因斯坦”高智商逻辑推理

2024-12-04 07:47:30
推荐回答(4个)
回答1:

不能一会儿用口算出来,直接在网上搜得了下面资料
1 2 3 4 5
挪威 丹麦 英国 德国 瑞典
黄色 蓝色 红色 绿色 白色
Dunhill Blend pall mall prinee bine msier
开水 茶 牛奶 咖啡 啤酒
猫 马 鸟 鱼 狗

#include

char* people[5] = {NULL};
char* color[5] = {NULL};
char* smoke[5] = {NULL};
char* drink[5] = {NULL};
char* pet[5] = {NULL};

/*
char* people[] = {"挪威","丹麦","英国","德国","瑞典"};
char* color[] = {"黄色","蓝色","红色","绿色","白色"};
char* smoke[] = {"Dunhill","Blend","Pall Mall","Prinee","Bine Masier"};
char* drink[] = {"开水","茶","牛奶","咖啡","啤酒"};
char* pet[] = {"猫","马","鸟","鱼","狗"};
*/

void print_single_result(const char* remark, char* a[])
{
cout << remark << endl;
for( int i = 0; i < 5; i ++ )
{
if( NULL == a[i] )
cout << "NULL";
else
cout << a[i];
cout << "\t" << flush;
}
cout << endl;
}

void print_result()
{
print_single_result("people", people);
print_single_result("color", color);
print_single_result("smoke", smoke);
print_single_result("drink", drink);
print_single_result("pet", pet);
}

int foo(const int level);

int main()
{
if( 0 == foo(0) )
{
print_result();
}
return 0;
}

Top

{
/*
0. (drink[2]=="牛奶")
1. (people[0]=="挪威")
2. (people[i]=="英国"&&color[i]=="红色")
3. (people[i]=="瑞典"&&pet[i]=="狗")
4. (people[i]=="丹麦"&&drink[i]=="茶")
5. (color[i]=="绿色"&&drink[i]=="咖啡")
6. (smoke[i]=="Bine Masier"&&drink[i]=="啤酒")
7. (smoke[i]=="Pall Mall"&&pet[i]=="鸟")
8. (color[i]=="黄色"&&smoke[i]=="Dunhill")
9. (people[i]=="德国"&&smoke[i]=="Prinee")
10. (color[i]=="绿色"&&color[j]=="白色"&&(i 11. (smoke[i]=="Dunhill"&&pet[j]=="马"&&(i=j-1||i=j+1))
12. (smoke[i]=="Blend"&&pet[j]=="猫"&&(i=j-1||i=j+1))
13. (people[i]=="挪威"&&color[j]=="蓝色"&&(i=j-1||i=j+1))
14. (drink[i]=="开水"&&smoke[j]=="Blend"&&(i=j-1||i=j+1))
*/
switch(level)
{
case 0 :
{
int isNull = 0;
if( drink[2] != NULL && strcmp(drink[2],"牛奶") ) return 1;
if( drink[2] == NULL ) isNull = 1;
if( isNull ) drink[2] = "牛奶";
if( 0 == foo(level+1) ) return 0;
if( isNull ) drink[2] = NULL;
return 1;
}
break;
case 1 :
{
int isNull = 0;
if( people[0] != NULL && strcmp(people[0],"挪威") ) return 1;
if( people[0] == NULL ) isNull = 1;
if( isNull ) people[0] = "挪威";
if( 0 == foo(level+1) ) return 0;
if( isNull ) people[0] = NULL;
return 1;
}
break;
case 2 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( people[i] != NULL && strcmp(people[i],"英国") ) continue;
if( color[i] != NULL && strcmp(color[i],"红色") ) continue;
if( people[i] == NULL ) isNull1 = 1;
if( color[i] == NULL ) isNull2 = 1;
if( isNull1 ) people[i] = "英国";
if( isNull2 ) color[i] = "红色";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) people[i] = NULL;
if( isNull2 ) color[i] = NULL;
}
return 1;
}
break;
case 3 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( people[i] != NULL && strcmp(people[i],"瑞典") ) continue;
if( pet[i] != NULL && strcmp(pet[i],"狗") ) continue;
if( people[i] == NULL ) isNull1 = 1;
if( pet[i] == NULL ) isNull2 = 1;
if( isNull1 ) people[i] = "瑞典";
if( isNull2 ) pet[i] = "狗";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) people[i] = NULL;
if( isNull2 ) pet[i] = NULL;
}
return 1;
}
break;
case 4 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( people[i] != NULL && strcmp(people[i],"丹麦") ) continue;
if( drink[i] != NULL && strcmp(drink[i],"茶") ) continue;
if( people[i] == NULL ) isNull1 = 1;
if( drink[i] == NULL ) isNull2 = 1;
if( isNull1 ) people[i] = "丹麦";
if( isNull2 ) drink[i] = "茶";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) people[i] = NULL;
if( isNull2 ) drink[i] = NULL;
}
return 1;
}
break;

Top

{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( color[i] != NULL && strcmp(color[i],"绿色") ) continue;
if( drink[i] != NULL && strcmp(drink[i],"咖啡") ) continue;
if( color[i] == NULL ) isNull1 = 1;
if( drink[i] == NULL ) isNull2 = 1;
if( isNull1 ) color[i] = "绿色";
if( isNull2 ) drink[i] = "咖啡";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) color[i] = NULL;
if( isNull2 ) drink[i] = NULL;
}
return 1;
}
break;
case 6 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( smoke[i] != NULL && strcmp(smoke[i],"Bine Masier") ) continue;
if( drink[i] != NULL && strcmp(drink[i],"啤酒") ) continue;
if( smoke[i] == NULL ) isNull1 = 1;
if( drink[i] == NULL ) isNull2 = 1;
if( isNull1 ) smoke[i] = "Bine Masier";
if( isNull2 ) drink[i] = "啤酒";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) smoke[i] = NULL;
if( isNull2 ) drink[i] = NULL;
}
return 1;
}
break;
case 7 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( smoke[i] != NULL && strcmp(smoke[i],"Pall Mall") ) continue;
if( pet[i] != NULL && strcmp(pet[i],"鸟") ) continue;
if( smoke[i] == NULL ) isNull1 = 1;
if( pet[i] == NULL ) isNull2 = 1;
if( isNull1 ) smoke[i] = "Pall Mall";
if( isNull2 ) pet[i] = "鸟";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) smoke[i] = NULL;
if( isNull2 ) pet[i] = NULL;
}
return 1;
}
break;
case 8 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( color[i] != NULL && strcmp(color[i],"黄色") ) continue;
if( smoke[i] != NULL && strcmp(smoke[i],"Dunhill") ) continue;
if( color[i] == NULL ) isNull1 = 1;
if( smoke[i] == NULL ) isNull2 = 1;
if( isNull1 ) color[i] = "黄色";
if( isNull2 ) smoke[i] = "Dunhill";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) color[i] = NULL;
if( isNull2 ) smoke[i] = NULL;
}
return 1;
}
break;
case 9 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0, isNull2=0;
if( people[i] != NULL && strcmp(people[i],"德国") ) continue;
if( smoke[i] != NULL && strcmp(smoke[i],"Prinee") ) continue;
if( people[i] == NULL ) isNull1 = 1;
if( smoke[i] == NULL ) isNull2 = 1;
if( isNull1 ) people[i] = "德国";
if( isNull2 ) smoke[i] = "Prinee";
if( 0 == foo(level+1) ) return 0;
if( isNull1 ) people[i] = NULL;
if( isNull2 ) smoke[i] = NULL;
}
return 1;
}
break;

Top

{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0;
if( color[i] != NULL && strcmp(color[i],"绿色") ) continue;
if( color[i] == NULL ) isNull1 = 1;
if( isNull1 ) color[i] = "绿色";
int j;
for( j = i+1; j < 5; j ++ )
{
int isNull2=0;
if( color[j] != NULL && strcmp(color[j],"白色") ) continue;
if( color[j] == NULL ) isNull2 = 1;
if( isNull2 ) color[j] = "白色";
if( 0 == foo(level+1) ) return 0;
if( isNull2 ) color[j] = NULL;
}
if( isNull1 ) color[i] = NULL;
}
return 1;
}
break;
case 11 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0;
if( smoke[i] != NULL && strcmp(smoke[i],"Dunhill") ) continue;
if( smoke[i] == NULL ) isNull1 = 1;
if( isNull1 ) smoke[i] = "Dunhill";
if( i-1>=0 )
{
int j = i-1;
int isNull2=0;
if( pet[j] == NULL || !strcmp(pet[j],"马") )
{
if( pet[j] == NULL ) isNull2 = 1;
if( isNull2 ) pet[j] = "马";
if( 0 == foo(level+1) ) return 0;
if( isNull2 ) pet[j] = NULL;
}
}
if( i+1<=4 )
{
int j = i+1;
int isNull2=0;
if( pet[j] == NULL || !strcmp(pet[j],"马") )
{
if( pet[j] == NULL ) isNull2 = 1;
if( isNull2 ) pet[j] = "马";
if( 0 == foo(level+1) ) return 0;
if( isNull2 ) pet[j] = NULL;
}
}
if( isNull1 ) smoke[i] = NULL;
}
return 1;
}
break;
case 12 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0;
if( smoke[i] != NULL && strcmp(smoke[i],"Blend") ) continue;
if( smoke[i] == NULL ) isNull1 = 1;
if( isNull1 ) smoke[i] = "Blend";
if( i-1>=0 )
{
int j = i-1;
int isNull2=0;
if( pet[j] == NULL || !strcmp(pet[j],"猫") )
{
if( pet[j] == NULL ) isNull2 = 1;
if( isNull2 ) pet[j] = "猫";
if( 0 == foo(level+1) ) return 0;
if( isNull2 ) pet[j] = NULL;
}
}
if( i+1<=4 )
{
int j = i+1;
int isNull2=0;
if( pet[j] == NULL || !strcmp(pet[j],"猫") )
{
if( pet[j] == NULL ) isNull2 = 1;
if( isNull2 ) pet[j] = "猫";
if( 0 == foo(level+1) ) return 0;
if( isNull2 ) pet[j] = NULL;
}
}
if( isNull1 ) smoke[i] = NULL;
}
return 1;
}
break;
case 13 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0;
if( people[i] != NULL && strcmp(people[i],"挪威") ) continue;
if( people[i] == NULL ) isNull1 = 1;
if( isNull1 ) people[i] = "挪威";
if( i-1>=0 )
{
int j = i-1;
int isNull2=0;
if( color[j] == NULL || !strcmp(color[j],"蓝色") )
{
if( color[j] == NULL ) isNull2 = 1;
if( isNull2 ) color[j] = "蓝色";
if( 0 == foo(level+1) ) return 0;
if( isNull2 ) color[j] = NULL;
}
}
if( i+1<=4 )
{
int j = i+1;
int isNull2=0;
if( color[j] == NULL || !strcmp(color[j],"蓝色") )
{
if( color[j] == NULL ) isNull2 = 1;
if( isNull2 ) color[j] = "蓝色";
if( 0 == foo(level+1) ) return 0;
if( isNull2 ) color[j] = NULL;
}
}
if( isNull1 ) people[i] = NULL;
}
return 1;
}
break;
case 14 :
{
int i = 0;
for( i = 0; i < 5; i ++ )
{
int isNull1=0;
if( drink[i] != NULL && strcmp(drink[i],"开水") ) continue;
if( drink[i] == NULL ) isNull1 = 1;
if( isNull1 ) drink[i] = "开水";
if( i-1>=0 )
{
int j = i-1;
int isNull2=0;
if( smoke[j] == NULL || !strcmp(smoke[j],"Blend") )
{
if( smoke[j] == NULL ) isNull2 = 1;
if( isNull2 ) smoke[j] = "Blend";
return 0;
}
}
if( i+1<=4 )
{
int j = i+1;
int isNull2=0;
if( smoke[j] == NULL || !strcmp(smoke[j],"Blend") )
{
if( smoke[j] == NULL ) isNull2 = 1;
if( isNull2 ) smoke[j] = "Blend";
return 0;
}
}
if( isNull1 ) drink[i] = NULL;
}
return 1;
}
break;
default :
break;
}
return 1;
}

回答2:

德国人养鱼
原因
因为第一栋房子里的是挪威人,又说挪威人住在蓝房子的旁边,所以就是说第二栋房子是蓝色的!
因为中间房子里的人喝牛奶,绿房子在白房子的左边和绿房子里的人喝咖啡可以看出第三栋房子是红色,第四栋是绿色,第五栋是白色,剩下的黄色也就是第一栋的了!
然后先把已知的都填上第三栋楼的人是英国人喝牛奶,第四栋喝咖啡,第一栋的人抽D!
因为抽D的人住在养马的旁边,所以第二栋就是养马的!
剩下的比较难...首先
从已知
抽混的人旁边住着喝水的或养猫的,所以抽混的就住在第二栋和~第四栋
从抽德国人抽P来看,德国人住在第二

五栋
从抽M的人养了只鸟来看,抽M的住在第三~五栋
从丑B的人喝啤酒来看,抽B的人住在第二栋或第五栋
以上我们可以列出一个图

B
P


M


P
M


B
P
M

然后我们再看
从上面的一些已知条件还有推测出的条件上来看,第一栋楼的人只能喝水,因为喝茶的丹麦人和抽B喝啤酒的都不可能住在第一栋楼!
因为抽混的人的住在喝水的旁边,所以可以知道抽混的住在第二栋楼,也由此可知抽B喝啤酒的只能是第五栋楼的主人了!
从丹麦人喝茶来看那么第二栋楼就是他的了!
从德国人抽P来看,他是住在第四栋楼的!
那现在剩下的最后一个就养狗的瑞典人相对应的楼是第五栋!
从抽M的人养了一只鸟和抽混的人住在养猫的人的附近,可以看出英国人是那个抽M的养鸟人,而挪威人是住在抽混的附近的养猫人!
当然剩下最最最最后面的就是德国人养猫这个答案了~~~
图:








绿






D

M
P
B(D:DUNHILL~混:混合~M:PALL
MALL~P:PRINCE~B:BLUE
MASTER)





累死我了,打字真累,我回答得对吧~~~对了解说要对着图看~~

回答3:

奥数中逻辑推理用画"表格"的方法做的.再讨论讨论就差不多了吧

回答4:

xcv