爱因斯坦的问题【求助】

浏览量:82 回复数:15
爱因斯坦的问题

爱因斯坦出了一道题,他说世界上有90%的人回答不出,看看你是否属于10%。

  内容:
  1. 有5栋5种颜色的房子
  2. 每一位房子的主人国籍都不同
  3. 这五个人每人只喝一个牌子的饮料,只抽一个牌子的香烟,只养一种宠物
  4. 没有人有相同的宠物,抽相同牌子的烟,喝相同牌子的饮料
  已知条件:
  1. 英国人住在红房子里
  2. 瑞典人养了一条狗
  3. 丹麦人喝茶
  4. 绿房子在白房子的左边
  5. 绿房子主人喝咖啡
  6. 抽PALL MALL

问题是:


谁养鱼?
  • 猫(1) ⒐天祈
  • 不想了 累
    下一个

  • 2008-01-25 00:53:25
  • 猫(3) imtk
  • 1. 有5栋5种颜色的房子
    > 2. 每一位房子的主人国籍都不同
    > 3. 这5个人每人只喝一个牌子的饮料, 只抽一个牌子的香烟, 只养一 种宠物
    > 4. 没有人有相同的宠物, 抽相同牌子的香烟, 喝相同的饮料
    > 已知条件:
    > 1. 英国人住在红房子里
    > 2. 瑞典人养了一条狗
    > 3. 丹麦人喝茶
    > 4. 绿房子在白房子左边
    > 5. 绿房子主人喝咖啡
    > 6. 抽PALL MALL烟的人养了一只鸟
    > 7. 黄房子主人抽DUNHILL烟
    > 8. 住在中间那间房子的人喝牛奶
    > 9. 挪威人住在第一间房子
    > 10. 抽混合烟的人住在养猫人的旁边
    > 11. 养马人住在DUNHILL烟的人旁边
    > 12. 抽BLUE MASTER烟的人喝啤酒
    > 13. 德国人抽PRINCE烟
    > 14. 挪威人住在蓝房子旁边
    > 15. 抽混合烟的人的邻居喝矿泉水
    > 问题是:
    > 谁养鱼?
  • 2008-01-25 01:21:15
  • 扑(4) imtk
  • 楼主题不给全 搞什么飞机我帮你
  • 2008-01-25 01:22:56
  • #include "stdafx.h"
    #include

    char* color_name[] =
    {
      "红",  "白",  "绿",  "蓝",  "黄",
    };
    enum
    {
      e_red, e_white, e_green, e_blue, e_yellow
    };

    char* nation_name[] =
    {
      "英国人",  "瑞典人",  "丹麦人",  "挪威人",  "德国人",
    };
    enum
    {
      e_briton, e_swede, e_dane, e_norwegian, e_german
    };

    char* drink_name[] =
    {
      "咖啡",  "茶",  "牛奶",  "啤酒",  "水",
    };
    enum
    {
      e_coffee, e_tea, e_milk, e_beer, e_water
    };

    char* smoke_name[] =
    {
      "pall mall",  "dunhill",  "blends",  "blue master",  "prince",
    };
    enum
    {
      e_pallmall, e_dunhill, e_blends, e_bluemaster, e_prince
    };

    char* pet_name[] =
    {
      "狗",  "猫",  "鸟",  "马",  "鱼",
    };
    enum
    {
      e_dog, e_cat, e_bird, e_horse, e_fish
    };

    const int house_count = 5;
    const int attrib_count = 5;
    const int tab_count = 5*4*3*2*1;
    char attrib_tab[tab_count][house_count];
    struct house_data
    {
      union
      {
        struct
        {
          int color;
          int nation;
          int drink;
          int smoke;
          int pet;
        };
        int attrib[5];
      };
    }house;
    void house_confirm()
    {
      int i;
      char* tab_color   = attrib_tab[house.color];
      char* tab_nation  = attrib_tab[house.nation];
      char* tab_drink   = attrib_tab[house.drink];
      char* tab_smoke   = attrib_tab[house.smoke];
      char* tab_pet    = attrib_tab[house.pet];

      //8. 住在中间房子的人喝牛奶
      if(tab_drink[2] != e_milk)
      {
        return;
      }
      for(i = 0; i < house_count; i ++)
      {
        // 1. 英国人住红色房子
        if(tab_nation[i] == e_briton)
        {
          if(tab_color[i] != e_red)
          {
            return;
          }
        }
        //2. 瑞典人养狗
        else if(tab_nation[i] == e_swede)
        {
          if(tab_pet[i] != e_dog)
          {
            return;
          }
        }
        //3. 丹麦人喝茶
        else if(tab_nation[i] == e_dane)
        {
          if(tab_drink[i] != e_tea)
          {
            return;
          }
        }
        //9. 挪威人住第一间房
        else if(tab_nation[i] == e_norwegian)
        {
          if(i > 0)
          {
            return;
          }
          //14. 挪威人住蓝色房子隔壁
          if(tab_color[1] != e_blue)
          {
            return;
          }
        }
        //13. 德国人抽prince香烟
        else if(tab_nation[i] == e_german)
        {
          if(tab_smoke[i] != e_prince)
          {
            return;
          }
        }
        //4. 绿色房子在白色房子左面
        if(tab_color[i] == e_green)
        {
          if(i >= house_count)
          {
            return;
          }
          if(tab_color[i+1] != e_white)
          {
            return;
          }
          //5. 绿色房子主人喝咖啡
          if(tab_drink[i] != e_coffee)
          {
            return;
          }
        }
        //6. 抽pall mall 香烟的人养鸟
        if(tab_smoke[i] == e_pallmall)
        {
          if(tab_pet[i] != e_bird)
          {
            return;
          }
        }
        //7. 黄色房子主人抽dunhill 香烟
        if(tab_color[i] == e_yellow)
        {
          if(tab_smoke[i] != e_dunhill)
          {
            return;
          }
        }
        //10. 抽blends香烟的人住在养猫的人隔壁
        //15. 抽blends香烟的人有一个喝水的邻居
        if(tab_smoke[i] == e_blends)
        {
          bool bCat = false;
          bool bWater = false;
          if(i < house_count-1)
          {
            if(tab_pet[i+1] == e_cat)
            {
              bCat = true;
            }
            if(tab_drink[i+1] == e_water)
            {
              bWater = true;
            }
          }
          if(i > 0)
          {
            if(tab_pet[i-1] == e_cat)
            {
              bCat = true;
            }
            if(tab_drink[i-1] == e_water)
            {
              bWater = true;
            }
          }
          if(!bCat || !bWater)
          {
            return;
          }
        }
        //11. 养马的人住抽dunhill 香烟的人隔壁
        else if(tab_smoke[i] == e_dunhill)
        {
          bool bHorse = false;
          if(i < house_count-1)
          {
            if(tab_pet[i+1] == e_horse)
            {
              bHorse = true;
            }
          }
          if(i > 0)
          {
            if(tab_pet[i-1] == e_horse)
            {
              bHorse = true;
            }
          }
          if(!bHorse)
          {
            return;
          }
        }
        //12. 抽blue master的人喝啤酒
        else if(tab_smoke[i] == e_bluemaster)
        {
          if(tab_drink[i] != e_beer)
          {
            return;
          }
        }
      }
      printf("Find\n");

      printf("color\tnation\tdrink\tpet\tsmoke\n");
      for(i = 0; i < house_count; i ++)
      {
        printf("%s\t%s\t%s\t%s\t%s\n",
          color_name[tab_color[i]],
          nation_name[tab_nation[i]],
          drink_name[tab_drink[i]],
          pet_name[tab_pet[i]],
          smoke_name[tab_smoke[i]]
          );
      }
      return;
    }
    void house_walk(int attrib)
    {
      int a = attrib + 1;
      for(int i = 0; i < tab_count; i ++)
      {
        house.attrib[attrib] = i;

        switch(attrib)
        {
        //  int color;
        case 0:
          //14. 挪威人住蓝色房子隔壁
          if(attrib_tab[i][1] != e_blue)
          {
            continue;
          }
          break;
        //  int nation;
        case 1:
          //9. 挪威人住第一间房
          if(attrib_tab[i][0] != e_norwegian)
          {
            continue;
          }
          break;
        //  int drink;
        case 2:
          //8. 住在中间房子的人喝牛奶
          if(attrib_tab[i][2] != e_milk)
          {
            continue;
          }
          {
            bool bContinue = false;
            for(int h = 0; h < house_count; h ++)
            {
              if(attrib_tab[i][h] == e_tea)
              {
                if(attrib_tab[house.nation][h] != e_dane)
                {
                  bContinue = true;
                  break;
                }
              }
              else if(attrib_tab[i][h] == e_coffee)
              {
                if(attrib_tab[house.color][h] != e_green)
                {
                  bContinue = true;
                  break;
                }
              }
            }
            if(bContinue)
            {
              continue;
            }
          }
          break;
        //  int smoke;
        case 3:
          {
            bool bContinue = false;
            for(int h = 0; h < house_count; h ++)
            {
              if(attrib_tab[i][h] == e_dunhill)
              {
                if(attrib_tab[house.color][h] != e_yellow)
                {
                  bContinue = true;
                  break;
                }
              }
              else if(attrib_tab[i][h] == e_bluemaster)
              {
                if(attrib_tab[house.drink][h] != e_beer)
                {
                  bContinue = true;
                  break;
                }
              }
            }
            if(bContinue)
            {
              continue;
            }
          }
          break;
        //  int pet;
        }
        
        if(a >= attrib_count)
        {
          house_confirm();
        }
        else
        {
          house_walk(attrib+1);
        }
      }
    }

    void gen_tab(int h, int& index)
    {
      int i;
      for(i = 0; i < house_count; i ++)
      {
        int j;
        for(j = 0; j < h; j ++)
        {
          if(i == attrib_tab[index][j])
          {
            goto lable_next;
          }
        }
        attrib_tab[index][h]  = i;
        if(h == house_count-1)
        {
          index ++;
          attrib_tab[index][0] = attrib_tab[index-1][0];
          attrib_tab[index][1] = attrib_tab[index-1][1];
          attrib_tab[index][2] = attrib_tab[index-1][2];
          attrib_tab[index][3] = attrib_tab[index-1][3];
          return;
        }
        gen_tab(h+1, index);
    lable_next:;
      }
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
      int index = 0;
      gen_tab(0, index);
      house_walk(0);
      getch();
      return 0;
    }
  • 2008-01-25 01:23:12
  • 扑(6) imtk
  • 再问一个,谁养楼主
  • 2008-01-25 01:29:57
  • 扑(8) endymionzxt
  • 留名!!
    明天上班的时候思考~~~~
  • 2008-01-25 02:10:23
  • 扑(10) 暴风雪╃
  • 请问这道题的原版英文版在哪里?
  • 2008-01-25 06:22:34
  • 扑(12) apple753
  • 看图明了

  • 2008-01-25 09:44:10
  • 猫(13) kinglei
  • 90%的人回答不出来?!
    看来通过此帖我已经发现地球人超过2000亿了。

    楼主该回火星了!
  • 2008-01-25 10:34:05
  • 猫(15) 莫可决
  • 5L是偶像
  • 2008-01-25 13:23:34