爱因斯坦”高智商逻辑推理
题目二:“爱因斯坦”高智商逻辑推理题目描述:a.有五栋五种颜色的房子b.每一位房子的主人国籍都不同c.这五个人每人只喝一种饮料,只抽一种牌子的香烟,只养一种宠物d.没有人...
题 目 二:“爱因斯坦”高智商逻辑推理
题目描述:a. 有五栋五种颜色的房子 b. 每一位房子的主人国籍都不同 c. 这五个人每人只喝一种饮料,只抽一种牌子的香烟,只养一种宠物 d. 没有人有相同的宠物,抽相同牌子的香烟,喝相同的饮料 条件提示: 1 英国人住在红房子里 2 瑞典人养了一条狗 3 丹麦人喝茶 4 绿房子在白房子左边 5 绿房子主人喝咖啡 6 抽 PALL MALL 烟的人养了一只鸟 7 黄房子主人抽 DUNHILL 烟 8 住在中间那间房子的人喝牛奶 9 挪威人住第一间房子 10 抽混合烟的人住在养猫人的旁边 11 养马人住在 DUNHILL 烟的人旁边 12 抽 BLUE MASTER 烟的人喝啤酒 13 德国人抽 PRINCE 烟 14 挪威人住在蓝房子旁边 15 抽混合烟的人的邻居喝矿泉水。问题是:谁养鱼 (1)瑞典人 (2)英国人 (3)挪威人 (4)德国人 (5)丹麦人。
基本要求:(1)根据a ~ d的要求以及1~15的条件编程实现问题求解;
(2)注意数据结构的选择,实物演示时要求讲出程序原理;
提高要求:(1)有很好的图形界面显示和较先进的算法;
(2)能将“房子-主人-饮料-香烟-饮料”的所有答案列出。
设计提示:本题答案唯一,一种常见的方法是根据给定条件用case或if语句穷举;此题数据结构的选取相当关键,数据结构选取失败将影响程序的实现;可以用递归来实现。
(我要C或C++编程的代码) 展开
题目描述:a. 有五栋五种颜色的房子 b. 每一位房子的主人国籍都不同 c. 这五个人每人只喝一种饮料,只抽一种牌子的香烟,只养一种宠物 d. 没有人有相同的宠物,抽相同牌子的香烟,喝相同的饮料 条件提示: 1 英国人住在红房子里 2 瑞典人养了一条狗 3 丹麦人喝茶 4 绿房子在白房子左边 5 绿房子主人喝咖啡 6 抽 PALL MALL 烟的人养了一只鸟 7 黄房子主人抽 DUNHILL 烟 8 住在中间那间房子的人喝牛奶 9 挪威人住第一间房子 10 抽混合烟的人住在养猫人的旁边 11 养马人住在 DUNHILL 烟的人旁边 12 抽 BLUE MASTER 烟的人喝啤酒 13 德国人抽 PRINCE 烟 14 挪威人住在蓝房子旁边 15 抽混合烟的人的邻居喝矿泉水。问题是:谁养鱼 (1)瑞典人 (2)英国人 (3)挪威人 (4)德国人 (5)丹麦人。
基本要求:(1)根据a ~ d的要求以及1~15的条件编程实现问题求解;
(2)注意数据结构的选择,实物演示时要求讲出程序原理;
提高要求:(1)有很好的图形界面显示和较先进的算法;
(2)能将“房子-主人-饮料-香烟-饮料”的所有答案列出。
设计提示:本题答案唯一,一种常见的方法是根据给定条件用case或if语句穷举;此题数据结构的选取相当关键,数据结构选取失败将影响程序的实现;可以用递归来实现。
(我要C或C++编程的代码) 展开
4个回答
展开全部
不能一会儿用口算出来,直接在网上搜得了下面资料
1 2 3 4 5
挪威 丹麦 英国 德国 瑞典
黄色 蓝色 红色 绿色 白色
Dunhill Blend pall mall prinee bine msier
开水 茶 牛奶 咖啡 啤酒
猫 马 鸟 鱼 狗
#include <iostream.h>
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<j))
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;
}
1 2 3 4 5
挪威 丹麦 英国 德国 瑞典
黄色 蓝色 红色 绿色 白色
Dunhill Blend pall mall prinee bine msier
开水 茶 牛奶 咖啡 啤酒
猫 马 鸟 鱼 狗
#include <iostream.h>
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<j))
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;
}
展开全部
德国人养鱼
原因
因为第一栋房子里的是挪威人,又说挪威人住在蓝房子的旁边,所以就是说第二栋房子是蓝色的!
因为中间房子里的人喝牛奶,绿房子在白房子的左边和绿房子里的人喝咖啡可以看出第三栋房子是红色,第四栋是绿色,第五栋是白色,剩下的黄色也就是第一栋的了!
然后先把已知的都填上第三栋楼的人是英国人喝牛奶,第四栋喝咖啡,第一栋的人抽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)
猫
马
鸟
鱼
狗
累死我了,打字真累,我回答得对吧~~~对了解说要对着图看~~
原因
因为第一栋房子里的是挪威人,又说挪威人住在蓝房子的旁边,所以就是说第二栋房子是蓝色的!
因为中间房子里的人喝牛奶,绿房子在白房子的左边和绿房子里的人喝咖啡可以看出第三栋房子是红色,第四栋是绿色,第五栋是白色,剩下的黄色也就是第一栋的了!
然后先把已知的都填上第三栋楼的人是英国人喝牛奶,第四栋喝咖啡,第一栋的人抽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)
猫
马
鸟
鱼
狗
累死我了,打字真累,我回答得对吧~~~对了解说要对着图看~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2007-01-17
展开全部
奥数中逻辑推理用画"表格"的方法做的.再讨论讨论就差不多了吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
xcv
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询