1、在一条街上,有5座房子,喷了5种颜色。
2、每个房里住着不同国籍的人
3、每个人喝不同的饮料,抽不同品牌的香烟,养不同的宠物
问题是:谁养鱼?提示:
  1、英国人住红色房子
  2、瑞典人养狗
  3、丹麦人喝茶
  4、绿色房子在白色房子左面
  5、绿色房子主人喝咖啡
  6、抽Pall Mall 香烟的人养鸟
  7、黄色房子主人抽Dunhill 香烟
  8、住在中间房子的人喝牛奶
  9、 挪威人住第一间房
  10、抽Blends香烟的人住在养猫的人隔壁
  11、养马的人住抽Dunhill 香烟的人隔壁
  12、抽Blue Master的人喝啤酒
  13、德国人抽Prince香烟
  14、挪威人住蓝色房子隔壁
  15、抽Blends香烟的人有一个喝水的邻居
以上是爱因斯坦在20世纪初出的这个谜语。他说世界上有98%的人答不出来。请新秀们在36小时内尽快抢答(当然,没兴趣的就算了),
请星星们与36小时后对新秀们的答案做评价(相信您们一定能得出结果,机会留给新人吧)。
给出正确答案的前5人获得每人获10分,星星们评议出的特色奖、选择奖加获10分,
剩下的30分算是给参加评议的星星们的一点小意思,毕竟劳动付出精力了嘛。这一百分算是我的新年贺礼,祝大家快乐 :)

解决方案 »

  1.   

    第一房间:黄色,挪威人,喝水,抽Dunhill,养猫
    第二房间:蓝色,丹麦人,喝茶,抽Blends,养马
    第三房间:红色,英国人,喝牛奶,抽Pall Mall,养鸟
    第四房间:绿色,德国人,喝咖啡,抽Prince,养鱼
    第五房间:白色,瑞典人,喝啤酒,抽Blue Master,养狗
      

  2.   

    分析的出来,SQl语句没写的出来。。
      

  3.   

    springzfc真是高人啊。佩服佩服,但是没SQL不给分。
    没办法,谁让这里是SQL论坛呢。送个笑脸表示一下敬意 :)
      

  4.   

    靠,程序求解都不会,还SQL?
      

  5.   

    这个两年前花了一个小时就搞定了,现在用sql求解?没思路,看看~~~
      

  6.   

    Haiwer老兄:稍微忍一下吧 :)
      

  7.   

    cross join 
    ..
    cross join
    ..
      where ..
    and
    smoke=case when animal='鸟' then 'pall mall' else smoke end
    and
    smoke=case when color='黄' then 'dunhill' else smoke end
    ..总觉得这种做法太笨了. 应该用推理,不一定是用程序求解. 某些东西,用推理比程序写算法更快. 只要脑子和逻辑够清晰
      

  8.   

    fcuandy: 这个世界普通人多,聪明人少(比如我就是个普通人)
    普通人的办法可能看起来笨拙,但是没关系,计算机的作用就是帮助我们快速完成大量的重复笨拙的简单劳动 :)
    个人观点: 计算机编程:如果要给别人看,或让别人维护,那么简单的逻辑比精巧的算法更便宜。
      

  9.   

    推理所得:1. 挪威人:黄色,水,猫,Dunhill
    2. 丹麦人:蓝色,茶,马,Blends
    3. 英国人:红色,牛奶,鸟,Pall Mall
    4. 德国人:绿色,咖啡,鱼,Price
    5. 瑞典人:白色,啤酒,狗,Blue Master所以,德国人养鱼程序还有待考虑
    挺有意思的,呵呵
      

  10.   

    1:黄色,挪威人,喝水,抽Dunhill,养猫 
    2:蓝色,丹麦人,喝茶,抽Blends,养马 
    3:红色,英国人,喝牛奶,抽Pall   Mall,养鸟 
    4:绿色,德国人,喝咖啡,抽Prince,养鱼 
    5:白色,瑞典人,喝啤酒,抽Blue   Master,养狗
      

  11.   

    我搞了个很离谱的结果出来,但是好像没有问题declare @table table(id int ,country varchar(10),color varchar(10),drink varchar(10),cigarette varchar(10),pet varchar(100)) insert into @table select * from 
    (select 1  as id union select 2 union select 3 union select 4 union select 5) a,
    (select 'England'  as country union select 'Den' union select 'Sweden' union select 'Germany' union select 'Norway') b,
    (select 'red'  as color union select 'green' union select 'white' union select 'blue' union select 'yellow')c,
    (select 'tee'  as drink union select 'coffee' union select 'milk' union select 'Beer' union select 'water') d,
    (select 'PallMall'  as cigarette union select 'Dunhill' union select 'Blends' union select 'BlueMaster' union select 'Prince') e,
    (select 'dog'  as pet union select 'Bird' union select 'cat' union select 'horse' union select 'fish') f --以下14个delete对应的是除去第四个条件的14个初步过滤条件,暂不考虑隔壁的情况
    delete from @table where (country='England' and color<>'red')or (country<>'England' and color='red')
    delete from @table where (country='Sweden' and pet<>'dog')or (country<>'Sweden' and pet='dog')
    delete from @table where (country='Den' and drink<>'tee')or (country<>'Den' and drink='tee')
    --第四个条件暂时不考虑
    delete from @table where (color='green' and drink<>'coffee')or (color<>'green' and drink='coffee')
    delete from @table where (cigarette='PallMall' and pet<>'Bird')or (cigarette<>'PallMall' and pet='Bird')
    delete from @table where (color='yellow' and cigarette<>'Dunhill')or (color<>'yellow' and cigarette='Dunhill')
    delete from @table where (id=3 and drink<>'milk')or (id<>3 and drink='milk')
    delete from @table where (id=1 and country<>'Norway')or (id<>1 and country='Norway')
    delete from @table where (cigarette='Blends' and pet='cat')or (cigarette='Blends' and pet='cat')
    delete from @table where (cigarette='Dunhill' and pet='horse')or (cigarette='Dunhill' and pet='horse')
    delete from @table where (cigarette='BlueMaster' and drink<>'Beer')or (cigarette<>'BlueMaster' and drink='Beer')
    delete from @table where (cigarette='Prince' and country<>'Germany')or (cigarette<>'Prince' and country='Germany')
    delete from @table where (id=2 and color<>'blue')or (id<>2 and color='blue') 
    delete from @table where (cigarette='Blends' and drink='water')or (cigarette='Blends' and drink='water')
    --交叉得出所有的情况
     select * into #table_result from 
    (select id as id1,country as country1,color as color1,drink as drink1,cigarette as cigarette1,pet as pet1 from @table where id=1) a,
    (select id as id2,country as country2,color as color2,drink as drink2,cigarette as cigarette2,pet as pet2 from @table where id=2) b,
    (select id as id3,country as country3,color as color3,drink as drink3,cigarette as cigarette3,pet as pet3 from @table where id=3) c,
    (select id as id4,country as country4,color as color4,drink as drink4,cigarette as cigarette4,pet as pet4 from @table where id=4) d,
    (select id as id5,country as country5,color as color5,drink as drink5,cigarette as cigarette5,pet as pet5 from @table where id=5) e
    where a.country1<>b.country2 and a.country1<>c.country3 and a.country1<>d.country4 and a.country1<>e.country5
    and b.country2<>c.country3 and b.country2<>d.country4 and b.country2<>e.country5
    and c.country3<>d.country4 and c.country3<>e.country5 and d.country4<>e.country5
      and a.color1<>b.color2 and a.color1<>c.color3 and a.color1<>d.color4 and a.color1<>e.color5
    and b.color2<>c.color3 and b.color2<>d.color4 and b.color2<>e.color5
    and c.color3<>d.color4 and c.color3<>e.color5 and d.color4<>e.color5
      and a.drink1<>b.drink2 and a.drink1<>c.drink3 and a.drink1<>d.drink4 and a.drink1<>e.drink5
    and b.drink2<>c.drink3 and b.drink2<>d.drink4 and b.drink2<>e.drink5
    and c.drink3<>d.drink4 and c.drink3<>e.drink5 and d.drink4<>e.drink5 and
    a.cigarette1<>b.cigarette2 and a.cigarette1<>c.cigarette3 and a.cigarette1<>d.cigarette4 and a.cigarette1<>e.cigarette5
    and b.cigarette2<>c.cigarette3 and b.cigarette2<>d.cigarette4 and b.cigarette2<>e.cigarette5
    and c.cigarette3<>d.cigarette4 and c.cigarette3<>e.cigarette5 and d.cigarette4<>e.cigarette5 
    and a.pet1<>b.pet2 and a.pet1<>c.pet3 and a.pet1<>d.pet4 and a.pet1<>e.pet5
    and b.pet2<>c.pet3 and b.pet2<>d.pet4 and b.pet2<>e.pet5
    and c.pet3<>d.pet4 and c.pet3<>e.pet5 and d.pet4<>e.pet5
    --把考虑隔壁情况的结果列出
    select *  from #table_result where(
    (color1='green') or (color5='white') or 
    (color2='green' and color3='white') or (color2='green' and color4='white') or
    (color3='green' and color4='white') )
    and(
    (cigarette1='Blends' and pet2='cat') or (cigarette5='Blends' and pet4='cat') or 
    (cigarette2='Blends' and pet1='cat') or (cigarette2='Blends' and pet3='cat') or
    (cigarette3='Blends' and pet2='cat') or (cigarette3='Blends' and pet4='cat') or 
    (cigarette4='Blends' and pet3='cat') or (cigarette4='Blends' and pet5='cat')  
     )
    and(
    (cigarette1='Dunhill' and pet2='horse') or (cigarette5='Dunhill' and pet4='horse') or 
    (cigarette2='Dunhill' and pet1='horse') or (cigarette2='Dunhill' and pet3='horse') or
    (cigarette3='Dunhill' and pet2='horse') or (cigarette3='Dunhill' and pet4='horse') or 
    (cigarette4='Dunhill' and pet3='horse') or (cigarette4='Dunhill' and pet5='horse') )
    and(
    (cigarette1='Blends' and drink2='water') or (cigarette5='Blends' and drink4='water') or 
    (cigarette2='Blends' and drink1='water') or (cigarette2='Blends' and drink3='water') or
    (cigarette3='Blends' and drink2='water') or (cigarette3='Blends' and drink4='water') or 
    (cigarette4='Blends' and drink3='water') or (cigarette4='Blends' and drink5='water') )
    drop table #table_result/* 德国人养鱼的结果
    1 Norway yellow water Dunhill cat
    2 Den blue tee Blends horse
    3 England red milk PallMall Bird
    4 Germany green coffee Prince fish
    5 Sweden white Beer BlueMaster dog *//*  挪威人养鱼的结果也符合所有的15个条件
    1 Norway green coffee Blends fish
    2 Germany blue water Prince cat
    3 Sweden yellow milk Dunhill dog
    4 England red Beer BlueMaster horse
    5 Den white tee PallMall Bird
    *//*还有其他5条结果当中丹麦人也有可能养鱼*//*
    4、绿色房子在白色房子左面 
    这个条件是错误的?或者信息不足,(我已经假设1号房子在最左面了,否则这个条件是没有意义的)
    事实证明这E=MC^2出了个垃圾题目-_-|||

    */
      

  12.   

    jinjazz: 
    1) 感谢您的关注与参与
    2) 批评您的犯规others:
    革命尚未成功,同志仍需努力
      

  13.   

    其他这些结果有问题吗?1,Norway,yellow,water,Dunhill,cat
    2,Den,blue,tee,Blends,horse
    3,England,red,milk,PallMall,Bird
    4,Germany,green,coffee,Prince,fish
    5,Sweden,white,Beer,BlueMaster,dog1,Norway,green,coffee,Blends,fish
    2,Germany,blue,water,Prince,cat
    3,Sweden,yellow,milk,Dunhill,dog
    4,England,red,Beer,BlueMaster,horse
    5,Den,white,tee,PallMall,Bird1,Norway,green,coffee,PallMall,Bird
    2,Germany,blue,water,Prince,cat
    3,Sweden,white,milk,Blends,dog
    4,England,red,Beer,BlueMaster,horse
    5,Den,yellow,tee,Dunhill,fish1,Norway,green,coffee,PallMall,Bird
    2,Germany,blue,water,Prince,fish
    3,England,red,milk,Blends,horse
    4,Den,yellow,tee,Dunhill,cat
    5,Sweden,white,Beer,BlueMaster,dog1,Norway,green,coffee,PallMall,Bird
    2,Germany,blue,water,Prince,cat
    3,Sweden,white,milk,Blends,dog
    4,Den,yellow,tee,Dunhill,fish
    5,England,red,Beer,BlueMaster,horse1,Norway,green,coffee,PallMall,Bird
    2,Germany,blue,water,Prince,cat
    3,England,red,milk,Blends,horse
    4,Den,yellow,tee,Dunhill,fish
    5,Sweden,white,Beer,BlueMaster,dog1,Norway,green,coffee,PallMall,Bird
    2,Germany,blue,water,Prince,fish
    3,Sweden,white,milk,Blends,dog
    4,Den,yellow,tee,Dunhill,cat
    5,England,red,Beer,BlueMaster,horse
      

  14.   

    jinjazz:  
    1)   感谢您的关注与参与
    2)   批评您的犯规
    3)   赞赏您的怀疑与激情
    ..我个人会原谅您的others:
    革命尚未成功,同志仍需努力
      

  15.   

    〉〉不是了,   我是说,我也是用的这种笨办法写的. 
    〉〉推理的话,还好了,   写语句想不出来什么好办法.     可能是水平的问题,推理的东西,难以用语法表达出来这个是你的思路问题了,用计算机解题不应该加入逻辑推理,而是一步一步模拟或者穷举,
    所以就不应该用语法来表达推理的东西我以前用sql解过其他的智力问题,可以参考
    http://borland.mblogger.cn/jinjazz/posts/20298.aspx
      

  16.   

    这是一个三元五次方程组问题.呵呵我解出来是德国人住绿房子喝咖啡抽prince养鱼的
      

  17.   

    ...
    思路和近身剪完全一样,为什么我的结果只有一个呢?
    declare @t table (
    Num int,
    颜色 varchar(20),
    国籍 varchar(20),
    饮料 varchar(20),
    香烟 varchar(20),
    宠物 varchar(20)
    )---全部组合
    insert @t
    select *
    from (
    select 1 as num
    union all select 2
    union all select 3
    union all select 4
    union all select 5
    ) as n,(
    select '红色' as 颜色
    union all select '绿色'
    union all select '白色'
    union all select '黄色'
    union all select '蓝色'
    ) as c,(
    select '英国' as 国籍
    union all select '瑞典'
    union all select '丹麦'
    union all select '挪威'
    union all select '德国'
    ) as g,(
    select '茶' as 饮料
    union all select '咖啡'
    union all select '牛奶'
    union all select '啤酒'
    union all select '水'
    ) as d,(
    select 'Pall Mall' as 香烟
    union all select 'Dunhill'
    union all select 'Blends'
    union all select 'Blue Master'
    union all select 'Prince'
    ) as s,(
    select '狗' as 宠物
    union all select '鸟'
    union all select '猫'
    union all select '马'
    union all select '鱼'
    ) as a
    --按条件删除
    delete @t
    where 国籍='英国'
    and 颜色<>'红色'delete @t
    where 国籍<>'英国'
    and 颜色='红色'delete @t
    where 国籍='瑞典'
    and 宠物<>'狗'delete @t
    where 国籍<>'瑞典'
    and 宠物='狗'delete @t
    where 国籍='丹麦'
    and 饮料<>'茶'delete @t
    where 国籍<>'丹麦'
    and 饮料='茶'delete @t
    where 颜色='绿色'
    and 饮料<>'咖啡'delete @t
    where 颜色<>'绿色'
    and 饮料='咖啡'delete @t
    where 香烟='Pall Mall'
    and 宠物<>'鸟'delete @t
    where 香烟<>'Pall Mall'
    and 宠物='鸟'delete @t
    where 香烟='Dunhill'
    and 颜色<>'黄色'delete @t
    where 香烟<>'Dunhill'
    and 颜色='黄色'delete @t
    where num=3
    and 饮料<>'牛奶'delete @t
    where num<>3
    and 饮料='牛奶'delete @t
    where num=1
    and 国籍<>'挪威'delete @t
    where num<>1
    and 国籍='挪威'delete @t
    where 香烟='Blue Master'
    and 饮料<>'啤酒'delete @t
    where 香烟<>'Blue Master'
    and 饮料='啤酒'delete @t
    where 香烟='Prince'
    and 国籍<>'德国'delete @t
    where 香烟<>'Prince'
    and 国籍='德国'--筛选
    select * from @t a,@t b,@t c,@t d,@t e
    where a.num=1
    and b.num=2
    and c.num=3
    and d.num=4
    and e.num=5
    and a.国籍<>b.国籍
    and a.香烟<>b.香烟
    and a.饮料<>b.饮料
    and a.颜色<>b.颜色
    and a.宠物<>c.宠物and a.国籍<>c.国籍
    and a.香烟<>c.香烟
    and a.饮料<>c.饮料
    and a.颜色<>c.颜色
    and a.宠物<>c.宠物and a.宠物<>d.宠物
    and a.国籍<>d.国籍
    and a.香烟<>d.香烟
    and a.饮料<>d.饮料
    and a.颜色<>d.颜色
    and a.宠物<>d.宠物and a.宠物<>e.宠物
    and a.国籍<>e.国籍
    and a.香烟<>e.香烟
    and a.饮料<>e.饮料
    and a.颜色<>e.颜色
    and a.宠物<>e.宠物and b.宠物<>c.宠物
    and b.国籍<>c.国籍
    and b.香烟<>c.香烟
    and b.饮料<>c.饮料
    and b.颜色<>c.颜色
    and b.宠物<>c.宠物and b.宠物<>d.宠物
    and b.国籍<>d.国籍
    and b.香烟<>d.香烟
    and b.饮料<>d.饮料
    and b.颜色<>d.颜色
    and b.宠物<>d.宠物and b.宠物<>e.宠物
    and b.国籍<>e.国籍
    and b.香烟<>e.香烟
    and b.饮料<>e.饮料
    and b.颜色<>e.颜色
    and b.宠物<>e.宠物and c.宠物<>d.宠物
    and c.国籍<>d.国籍
    and c.香烟<>d.香烟
    and c.饮料<>d.饮料
    and c.颜色<>d.颜色
    and c.宠物<>d.宠物and c.宠物<>e.宠物
    and c.国籍<>e.国籍
    and c.香烟<>e.香烟
    and c.饮料<>e.饮料
    and c.颜色<>e.颜色
    and c.宠物<>e.宠物and d.宠物<>e.宠物
    and d.国籍<>e.国籍
    and d.香烟<>e.香烟
    and d.饮料<>e.饮料
    and d.颜色<>e.颜色
    and d.宠物<>e.宠物and (a.颜色='绿色' and b.颜色='白色'
    or b.颜色='绿色' and c.颜色='白色'
    or c.颜色='绿色' and d.颜色='白色'
    or d.颜色='绿色' and e.颜色='白色')and (b.宠物='猫' and (a.香烟='Blends' or c.香烟='Blends')
    or b.香烟='Blends' and (a.宠物='猫' or c.宠物='猫')
    or c.宠物='猫' and (b.香烟='Blends' or d.香烟='Blends')
    or c.香烟='Blends' and (b.宠物='猫' or d.宠物='猫')
    or d.宠物='猫' and (c.香烟='Blends' or e.香烟='Blends')
    or d.香烟='Blends' and (c.宠物='猫' or e.宠物='猫')
    )and (b.宠物='马' and (a.香烟='Dunhill' or c.香烟='Dunhill')
    or b.香烟='Dunhill' and (a.宠物='马' or c.宠物='马')
    or c.宠物='马' and (b.香烟='Dunhill' or d.香烟='Dunhill')
    or c.香烟='Dunhill' and (b.宠物='马' or d.宠物='马')
    or d.宠物='马' and (c.香烟='Dunhill' or e.香烟='Dunhill')
    or d.香烟='Dunhill' and (c.宠物='马' or e.宠物='马')
    )and (b.国籍='挪威' and (a.颜色='蓝色' or c.颜色='蓝色')
    or b.颜色='蓝色' and (a.国籍='挪威' or c.国籍='挪威')
    or c.国籍='挪威' and (b.颜色='蓝色' or d.颜色='蓝色')
    or c.颜色='蓝色' and (b.国籍='挪威' or d.国籍='挪威')
    or d.国籍='挪威' and (c.颜色='蓝色' or e.颜色='蓝色')
    or d.颜色='蓝色' and (c.国籍='挪威' or e.国籍='挪威')
    )and (b.饮料='水' and (a.香烟='Blends' or c.香烟='Blends')
    or b.香烟='Blends' and (a.饮料='水' or c.饮料='水')
    or c.饮料='水' and (b.香烟='Blends' or d.香烟='Blends')
    or c.香烟='Blends' and (b.饮料='水' or d.饮料='水')
    or d.饮料='水' and (c.香烟='Blends' or e.香烟='Blends')
    or d.香烟='Blends' and (c.饮料='水' or e.饮料='水')
    )
    --结果(用时5秒)
    Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   
    ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- 
    1           黄色                   挪威                   水                    Dunhill              猫                    2           蓝色                   丹麦                   茶                    Blends               马                    3           红色                   英国                   牛奶                   Pall Mall            鸟                    4           绿色                   德国                   咖啡                   Prince               鱼                    5           白色                   瑞典                   啤酒                   Blue Master          狗(所影响的行数为 1 行)
      

  18.   

    我是先建了几个表,再cross  join出你们最初声明的那个表的.
    都差不多.〉〉不是了,       我是说,我也是用的这种笨办法写的.   
    〉〉推理的话,还好了,       写语句想不出来什么好办法.           可能是水平的问题,推理的东西,难以用语法表达出来 这个是你的思路问题了,用计算机解题不应该加入逻辑推理,而是一步一步模拟或者穷举, 
    所以就不应该用语法来表达推理的东西 
    不过,我始终觉得,推理是可以用语法表达的,只不过是我水平未到.
      

  19.   

    to Haiwer 海阔天空先从结果看看,我的其他结果有问题吗?
      

  20.   

    1: 严重批评Haiwer
    2: 全面解禁
    3: 欢迎各位发布各自的脚本
    4: 欢迎各位对发布的脚本进行评议
    5: 调整给分策略(策略有待征集)
      

  21.   

    枪手:我相信您
    Haiwer:之所以定这样的规则目的是为新秀们提供一个锻炼机会,其实您老再忍过二十几个小时就够了。
      

  22.   

    to   Haiwer   海阔天空 有个地方错了 
     a.宠物<>c.宠物 --〉a.宠物<>b.宠物我们的区别是第四个条件理解不同,绿色的房子在白色房子的左面--〉左面<>隔壁的左面,而且你也试假设1号在最左面的
      

  23.   

    select *  from @t1 a,@t2 b,@t3 c,@t4 d,@t5 e,@t6 f
    where  (country='英国' and color='红色' or (color<>'红色' and country<>'英国')) --1
          and (country='瑞典' and pet='狗' or country<>'瑞典' and pet<>'狗')  --2
          and (country='丹麦' and drink='茶' or country<>'丹麦' and drink<>'茶') --3
          and not (no=1 and color='白色') and not (no=5 and color='绿色')  --4绿色房子在白色房子左面 
      and (color='绿色' and drink='咖啡' or color<>'绿色' and drink<>'咖啡') --5
      and (smoke='Pall Mall' and pet='鸟' or smoke<>'Pall Mall' and pet<>'鸟') --6抽Pall Mall   香烟的人养鸟 
          and (color='黄色' and smoke='Dunhill' or color<>'黄色' and smoke<>'Dunhill') --7黄色房子主人抽Dunhill   香烟
      and (no=3 and drink='牛奶' or no<>3 and drink<>'牛奶') --8、住在中间房子的人喝牛奶 
      and (country='挪威' and no=1 or country<>'挪威' and no<>1) --9
          and (smoke<>'Blends' or smoke='blends' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and pet='猫' 
    and color<>b.color and country<>c.country and drink<>d.drink and smoke<>'blend' and pet<>f.pet))
          and (pet<>'猫' or pet='猫' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) 
                 and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and smoke='Blends' and pet<>'猫'))
                           --10、抽Blends香烟的人住在养猫的人隔壁 
          and (pet<>'马' or pet='马' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and smoke='Dunhill'
                      and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
          and (smoke<>'Dunhill' or smoke='Dunhill' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and pet='马'
                     and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
          --11、养马的人住抽Dunhill   香烟的人隔壁 
          and (smoke='Blue Master' and drink='啤酒' or smoke<>'Blue Master' and drink<>'啤酒') --12、抽Blue   Master的人喝啤酒 
          and (country='德国' and drink='Prince' or country<>'德国' and drink<>'Prince') --13、德国人抽Prince香烟
      and (country<>'挪威' or country='挪威' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and color='蓝色'
                 and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
            --14、挪威人住蓝色房子隔壁 
          and (smoke<>'Blends' or smoke='Blends' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and drink='水'
            and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))      --15、抽Blends香烟的人有一个喝水的邻居 
    order by 6,3,1
    得出101条记录,还有1、在一条街上,有5座房子,喷了5种颜色。 
    2、每个房里住着不同国籍的人 
    3、每个人喝不同的饮料,抽不同品牌的香烟,养不同的宠物 
    3个基本条件未作筛选。
      

  24.   

    set nocount on
    declare @t1 table (no int)
    insert into @t1 values(1)
    insert into @t1 values(2)
    insert into @t1 values(3)
    insert into @t1 values(4)
    insert into @t1 values(5)
    declare @t2 table(color varchar(20))
    insert into @t2 values('红色')
    insert into @t2 values('白色')
    insert into @t2 values('绿色')
    insert into @t2 values('黄色')
    insert into @t2 values('蓝色')
    declare @t3 table(country varchar(20))
    insert into @t3 values ('英国')
    insert into @t3 values ('瑞典')
    insert into @t3 values ('丹麦')
    insert into @t3 values ('德国')
    insert into @t3 values ('挪威')
    declare @t4 table(drink varchar(20))
    insert into @t4 values('茶')
    insert into @t4 values('咖啡')
    insert into @t4 values('牛奶')
    insert into @t4 values('啤酒')
    insert into @t4 values('水')
    declare @t5 table(smoke varchar(20))
    insert into @t5 values('Pall Mall')
    insert into @t5 values('Dunhill')
    insert into @t5 values('Blends')
    insert into @t5 values('Blue Master')
    insert into @t5 values('Prince')
    declare @t6 table(pet varchar(20))
    insert into @t6 values('狗')
    insert into @t6 values('鸟')
    insert into @t6 values('猫')
    insert into @t6 values('马')
    insert into @t6 values('鱼')
    set nocount off
    select * into #tmp from @t1 a,@t2 b,@t3 c,@t4 d,@t5 e,@t6 f
    where  (country='英国' and color='红色' or color<>'红色' and country<>'英国') --1、英国人住红色房子 
          and (country='瑞典' and pet='狗' or country<>'瑞典' and pet<>'狗')  --2、瑞典人养狗 
          and (country='丹麦' and drink='茶' or country<>'丹麦' and drink<>'茶') --3、丹麦人喝茶 
      and (color<>'白色' or  color='白色' and exists(select * from @t1,@t2,@t3,@t4,@t5 where no=a.no-1 and color='绿色'
      and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))           
                --4绿色房子在白色房子左面 
      and (color='绿色' and drink='咖啡' or color<>'绿色' and drink<>'咖啡') --5 绿色房子主人喝咖啡 
      and (smoke='Pall Mall' and pet='鸟' or smoke<>'Pall Mall' and pet<>'鸟') --6抽Pall Mall   香烟的人养鸟 
          and (color='黄色' and smoke='Dunhill' or color<>'黄色' and smoke<>'Dunhill') --7黄色房子主人抽Dunhill   香烟
      and (no=3 and drink='牛奶' or no<>3 and drink<>'牛奶') --8、住在中间房子的人喝牛奶 
      and (country='挪威' and no=1 or country<>'挪威' and no<>1) --9挪威人住第一间房 

          and (smoke<>'Blends' 
    or smoke='blends' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and pet='猫' 
    and color<>b.color and country<>c.country and drink<>d.drink and smoke<>'blend' and pet<>f.pet))
                           --10、抽Blends香烟的人住在养猫的人隔壁       and (pet<>'马' or pet='马' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and smoke='Dunhill'
                      and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
          --11、养马的人住抽Dunhill   香烟的人隔壁       and (smoke='Blue Master' and drink='啤酒' or smoke<>'Blue Master' and drink<>'啤酒') --12、抽Blue Master的人喝啤酒 
          and (country='德国' and smoke='Prince' or country<>'德国' and smoke<>'Prince') --13、德国人抽Prince香烟
         
      and (country<>'挪威' 
              or country='挪威' and  exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or  no=a.no-1) and color='蓝色'
                 and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
            --14、挪威人住蓝色房子隔壁 
          and (smoke<>'Blends' or smoke='Blends' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and drink='水'
            and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
          --15、抽Blends香烟的人有一个喝水的邻居 
         
    order by 6,3,1
      

  25.   

    set nocount on
    declare @t1 table (no int)
    insert into @t1 values(1)
    insert into @t1 values(2)
    insert into @t1 values(3)
    insert into @t1 values(4)
    insert into @t1 values(5)
    declare @t2 table(color varchar(20))
    insert into @t2 values('红色')
    insert into @t2 values('白色')
    insert into @t2 values('绿色')
    insert into @t2 values('黄色')
    insert into @t2 values('蓝色')
    declare @t3 table(country varchar(20))
    insert into @t3 values ('英国')
    insert into @t3 values ('瑞典')
    insert into @t3 values ('丹麦')
    insert into @t3 values ('德国')
    insert into @t3 values ('挪威')
    declare @t4 table(drink varchar(20))
    insert into @t4 values('茶')
    insert into @t4 values('咖啡')
    insert into @t4 values('牛奶')
    insert into @t4 values('啤酒')
    insert into @t4 values('水')
    declare @t5 table(smoke varchar(20))
    insert into @t5 values('Pall Mall')
    insert into @t5 values('Dunhill')
    insert into @t5 values('Blends')
    insert into @t5 values('Blue Master')
    insert into @t5 values('Prince')
    declare @t6 table(pet varchar(20))
    insert into @t6 values('狗')
    insert into @t6 values('鸟')
    insert into @t6 values('猫')
    insert into @t6 values('马')
    insert into @t6 values('鱼')
    set nocount off
    select *  from @t1 a,@t2 b,@t3 c,@t4 d,@t5 e,@t6 f
    where  (country='英国' and color='红色' or color<>'红色' and country<>'英国') --1、英国人住红色房子 
          and (country='瑞典' and pet='狗' or country<>'瑞典' and pet<>'狗')  --2、瑞典人养狗 
          and (country='丹麦' and drink='茶' or country<>'丹麦' and drink<>'茶') --3、丹麦人喝茶 
      and (color<>'白色' or  color='白色' and exists(select * from @t1,@t2,@t3,@t4,@t5 where no=a.no-1 and color='绿色'
      and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))           
                --4绿色房子在白色房子左面 
      and (color='绿色' and drink='咖啡' or color<>'绿色' and drink<>'咖啡') --5 绿色房子主人喝咖啡 
      and (smoke='Pall Mall' and pet='鸟' or smoke<>'Pall Mall' and pet<>'鸟') --6抽Pall Mall   香烟的人养鸟 
          and (color='黄色' and smoke='Dunhill' or color<>'黄色' and smoke<>'Dunhill') --7黄色房子主人抽Dunhill   香烟
      and (no=3 and drink='牛奶' or no<>3 and drink<>'牛奶') --8、住在中间房子的人喝牛奶 
      and (country='挪威' and no=1 or country<>'挪威' and no<>1) --9挪威人住第一间房 

          and (smoke<>'Blends' 
    or smoke='blends' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and pet='猫' 
    and color<>b.color and country<>c.country and drink<>d.drink and smoke<>'blend' and pet<>f.pet))
                           --10、抽Blends香烟的人住在养猫的人隔壁       and (pet<>'马' or pet='马' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and smoke='Dunhill'
                      and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
          --11、养马的人住抽Dunhill   香烟的人隔壁       and (smoke='Blue Master' and drink='啤酒' or smoke<>'Blue Master' and drink<>'啤酒') --12、抽Blue Master的人喝啤酒 
          and (country='德国' and smoke='Prince' or country<>'德国' and smoke<>'Prince') --13、德国人抽Prince香烟
         
      and (country<>'挪威' 
              or country='挪威' and  exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or  no=a.no-1) and color='蓝色'
                 and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
            --14、挪威人住蓝色房子隔壁 
          and (smoke<>'Blends' or smoke='Blends' and exists(select * from @t1,@t2,@t3,@t4,@t5,@t6 where (no=a.no+1 or no=a.no-1) and drink='水'
            and color<>b.color and country<>c.country and drink<>d.drink and smoke<>e.smoke and pet<>f.pet))
          --15、抽Blends香烟的人有一个喝水的邻居 
         
    order by 6,3,1
    得出67条记录,好象邻居的项目还可再过滤,不知如何处理
      

  26.   

    是否“左面 <> 隔壁的左面”我觉得是个语文问题如果 左面 <> 隔壁的左面,那就没必要说了,所以我假定 左面 = 隔壁的左面
    ps:这帖子打开得太慢了,也许我的电脑有点问题
      

  27.   


    --1、坚持   左面   =   隔壁的左面 
    --2、修正笔误
    --3、把有左面和第一字样的条件4 9合并,适合第一是左边第一和第一是右边第一两种情况求解declare @t table (
    Num int,
    颜色 varchar(20),
    国籍 varchar(20),
    饮料 varchar(20),
    香烟 varchar(20),
    宠物 varchar(20)
    )---全部组合
    insert @t
    select *
    from (
    select 1 as num
    union all select 2
    union all select 3
    union all select 4
    union all select 5
    ) as n,(
    select '红色' as 颜色
    union all select '绿色'
    union all select '白色'
    union all select '黄色'
    union all select '蓝色'
    ) as c,(
    select '英国' as 国籍
    union all select '瑞典'
    union all select '丹麦'
    union all select '挪威'
    union all select '德国'
    ) as g,(
    select '茶' as 饮料
    union all select '咖啡'
    union all select '牛奶'
    union all select '啤酒'
    union all select '水'
    ) as d,(
    select 'Pall Mall' as 香烟
    union all select 'Dunhill'
    union all select 'Blends'
    union all select 'Blue Master'
    union all select 'Prince'
    ) as s,(
    select '狗' as 宠物
    union all select '鸟'
    union all select '猫'
    union all select '马'
    union all select '鱼'
    ) as a
    --按条件删除
    delete @t
    where 国籍='英国'
    and 颜色<>'红色'delete @t
    where 国籍<>'英国'
    and 颜色='红色'delete @t
    where 国籍='瑞典'
    and 宠物<>'狗'delete @t
    where 国籍<>'瑞典'
    and 宠物='狗'delete @t
    where 国籍='丹麦'
    and 饮料<>'茶'delete @t
    where 国籍<>'丹麦'
    and 饮料='茶'delete @t
    where 颜色='绿色'
    and 饮料<>'咖啡'delete @t
    where 颜色<>'绿色'
    and 饮料='咖啡'delete @t
    where 香烟='Pall Mall'
    and 宠物<>'鸟'delete @t
    where 香烟<>'Pall Mall'
    and 宠物='鸟'delete @t
    where 香烟='Dunhill'
    and 颜色<>'黄色'delete @t
    where 香烟<>'Dunhill'
    and 颜色='黄色'delete @t
    where num=3
    and 饮料<>'牛奶'delete @t
    where num<>3
    and 饮料='牛奶'/*
    delete @t
    where num=1
    and 国籍<>'挪威'delete @t
    where num<>1
    and 国籍='挪威'
    */delete @t
    where 香烟='Blue Master'
    and 饮料<>'啤酒'delete @t
    where 香烟<>'Blue Master'
    and 饮料='啤酒'delete @t
    where 香烟='Prince'
    and 国籍<>'德国'delete @t
    where 香烟<>'Prince'
    and 国籍='德国'--筛选
    select * from @t a,@t b,@t c,@t d,@t e
    where a.num=1
    and b.num=2
    and c.num=3
    and d.num=4
    and e.num=5
    and a.国籍<>b.国籍
    and a.香烟<>b.香烟
    and a.饮料<>b.饮料
    and a.颜色<>b.颜色
    and a.宠物<>b.宠物and a.国籍<>c.国籍
    and a.香烟<>c.香烟
    and a.饮料<>c.饮料
    and a.颜色<>c.颜色
    and a.宠物<>c.宠物and a.宠物<>d.宠物
    and a.国籍<>d.国籍
    and a.香烟<>d.香烟
    and a.饮料<>d.饮料
    and a.颜色<>d.颜色
    and a.宠物<>d.宠物and a.宠物<>e.宠物
    and a.国籍<>e.国籍
    and a.香烟<>e.香烟
    and a.饮料<>e.饮料
    and a.颜色<>e.颜色
    and a.宠物<>e.宠物and b.宠物<>c.宠物
    and b.国籍<>c.国籍
    and b.香烟<>c.香烟
    and b.饮料<>c.饮料
    and b.颜色<>c.颜色
    and b.宠物<>c.宠物and b.宠物<>d.宠物
    and b.国籍<>d.国籍
    and b.香烟<>d.香烟
    and b.饮料<>d.饮料
    and b.颜色<>d.颜色
    and b.宠物<>d.宠物and b.宠物<>e.宠物
    and b.国籍<>e.国籍
    and b.香烟<>e.香烟
    and b.饮料<>e.饮料
    and b.颜色<>e.颜色
    and b.宠物<>e.宠物and c.宠物<>d.宠物
    and c.国籍<>d.国籍
    and c.香烟<>d.香烟
    and c.饮料<>d.饮料
    and c.颜色<>d.颜色
    and c.宠物<>d.宠物and c.宠物<>e.宠物
    and c.国籍<>e.国籍
    and c.香烟<>e.香烟
    and c.饮料<>e.饮料
    and c.颜色<>e.颜色
    and c.宠物<>e.宠物and d.宠物<>e.宠物
    and d.国籍<>e.国籍
    and d.香烟<>e.香烟
    and d.饮料<>e.饮料
    and d.颜色<>e.颜色
    and d.宠物<>e.宠物
    /*
    and (a.颜色='绿色' and b.颜色='白色'
    or b.颜色='绿色' and c.颜色='白色'
    or c.颜色='绿色' and d.颜色='白色'
    or d.颜色='绿色' and e.颜色='白色')
    */
    and (b.宠物='猫' and (a.香烟='Blends' or c.香烟='Blends')
    or b.香烟='Blends' and (a.宠物='猫' or c.宠物='猫')
    or c.宠物='猫' and (b.香烟='Blends' or d.香烟='Blends')
    or c.香烟='Blends' and (b.宠物='猫' or d.宠物='猫')
    or d.宠物='猫' and (c.香烟='Blends' or e.香烟='Blends')
    or d.香烟='Blends' and (c.宠物='猫' or e.宠物='猫')
    )and (b.宠物='马' and (a.香烟='Dunhill' or c.香烟='Dunhill')
    or b.香烟='Dunhill' and (a.宠物='马' or c.宠物='马')
    or c.宠物='马' and (b.香烟='Dunhill' or d.香烟='Dunhill')
    or c.香烟='Dunhill' and (b.宠物='马' or d.宠物='马')
    or d.宠物='马' and (c.香烟='Dunhill' or e.香烟='Dunhill')
    or d.香烟='Dunhill' and (c.宠物='马' or e.宠物='马')
    )and (b.国籍='挪威' and (a.颜色='蓝色' or c.颜色='蓝色')
    or b.颜色='蓝色' and (a.国籍='挪威' or c.国籍='挪威')
    or c.国籍='挪威' and (b.颜色='蓝色' or d.颜色='蓝色')
    or c.颜色='蓝色' and (b.国籍='挪威' or d.国籍='挪威')
    or d.国籍='挪威' and (c.颜色='蓝色' or e.颜色='蓝色')
    or d.颜色='蓝色' and (c.国籍='挪威' or e.国籍='挪威')
    )and (b.饮料='水' and (a.香烟='Blends' or c.香烟='Blends')
    or b.香烟='Blends' and (a.饮料='水' or c.饮料='水')
    or c.饮料='水' and (b.香烟='Blends' or d.香烟='Blends')
    or c.香烟='Blends' and (b.饮料='水' or d.饮料='水')
    or d.饮料='水' and (c.香烟='Blends' or e.香烟='Blends')
    or d.香烟='Blends' and (c.饮料='水' or e.饮料='水')
    )and (    --左边是1
    a.国籍='挪威' and (a.颜色='绿色' and b.颜色='白色'
    or b.颜色='绿色' and c.颜色='白色'
    or c.颜色='绿色' and d.颜色='白色'
    or d.颜色='绿色' and e.颜色='白色')
    or
    --左边是5
    e.国籍='挪威' and (e.颜色='绿色' and d.颜色='白色'
    or d.颜色='绿色' and c.颜色='白色'
    or c.颜色='绿色' and b.颜色='白色'
    or b.颜色='绿色' and a.颜色='白色')

    --结果
    Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   
    ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- 
    1           白色                   瑞典                   啤酒                   Blue Master          狗                    2           绿色                   德国                   咖啡                   Prince               鱼                    3           红色                   英国                   牛奶                   Pall Mall            鸟                    4           蓝色                   丹麦                   茶                    Blends               马                    5           黄色                   挪威                   水                    Dunhill              猫
    1           黄色                   挪威                   水                    Dunhill              猫                    2           蓝色                   丹麦                   茶                    Blends               马                    3           红色                   英国                   牛奶                   Pall Mall            鸟                    4           绿色                   德国                   咖啡                   Prince               鱼                    5           白色                   瑞典                   啤酒                   Blue Master          狗(所影响的行数为 2 行)--结论:两个结果只是倒了下次序,答案是唯一的,德国人养鱼
    --至于其他写法得出很多结果的,应该是条件写漏了--帖子太慢,没有仔细看
      

  28.   

    Haiwer 
    海阔天空 是否“左面   <>   隔壁的左面”我觉得是个语文问题 ----------------这个问题我倒是忽略了,我推理的时候是作为 “左面 = 隔壁的左面”
    有必要再看看 “左面 <> 隔壁的左面”的情况 
     
      

  29.   


    --上一个回复假定了 最左边是第一,修正下 declare @t table (
    Num int,
    颜色 varchar(20),
    国籍 varchar(20),
    饮料 varchar(20),
    香烟 varchar(20),
    宠物 varchar(20)
    )---全部组合
    insert @t
    select *
    from (
    select 1 as num
    union all select 2
    union all select 3
    union all select 4
    union all select 5
    ) as n,(
    select '红色' as 颜色
    union all select '绿色'
    union all select '白色'
    union all select '黄色'
    union all select '蓝色'
    ) as c,(
    select '英国' as 国籍
    union all select '瑞典'
    union all select '丹麦'
    union all select '挪威'
    union all select '德国'
    ) as g,(
    select '茶' as 饮料
    union all select '咖啡'
    union all select '牛奶'
    union all select '啤酒'
    union all select '水'
    ) as d,(
    select 'Pall Mall' as 香烟
    union all select 'Dunhill'
    union all select 'Blends'
    union all select 'Blue Master'
    union all select 'Prince'
    ) as s,(
    select '狗' as 宠物
    union all select '鸟'
    union all select '猫'
    union all select '马'
    union all select '鱼'
    ) as a
    --按条件删除
    delete @t
    where 国籍='英国'
    and 颜色<>'红色'delete @t
    where 国籍<>'英国'
    and 颜色='红色'delete @t
    where 国籍='瑞典'
    and 宠物<>'狗'delete @t
    where 国籍<>'瑞典'
    and 宠物='狗'delete @t
    where 国籍='丹麦'
    and 饮料<>'茶'delete @t
    where 国籍<>'丹麦'
    and 饮料='茶'delete @t
    where 颜色='绿色'
    and 饮料<>'咖啡'delete @t
    where 颜色<>'绿色'
    and 饮料='咖啡'delete @t
    where 香烟='Pall Mall'
    and 宠物<>'鸟'delete @t
    where 香烟<>'Pall Mall'
    and 宠物='鸟'delete @t
    where 香烟='Dunhill'
    and 颜色<>'黄色'delete @t
    where 香烟<>'Dunhill'
    and 颜色='黄色'delete @t
    where num=3
    and 饮料<>'牛奶'delete @t
    where num<>3
    and 饮料='牛奶'/*
    delete @t
    where num=1
    and 国籍<>'挪威'delete @t
    where num<>1
    and 国籍='挪威'
    */delete @t
    where 香烟='Blue Master'
    and 饮料<>'啤酒'delete @t
    where 香烟<>'Blue Master'
    and 饮料='啤酒'delete @t
    where 香烟='Prince'
    and 国籍<>'德国'delete @t
    where 香烟<>'Prince'
    and 国籍='德国'--筛选
    select * from @t a,@t b,@t c,@t d,@t e
    where a.num=1
    and b.num=2
    and c.num=3
    and d.num=4
    and e.num=5
    and a.国籍<>b.国籍
    and a.香烟<>b.香烟
    and a.饮料<>b.饮料
    and a.颜色<>b.颜色
    and a.宠物<>b.宠物and a.国籍<>c.国籍
    and a.香烟<>c.香烟
    and a.饮料<>c.饮料
    and a.颜色<>c.颜色
    and a.宠物<>c.宠物and a.宠物<>d.宠物
    and a.国籍<>d.国籍
    and a.香烟<>d.香烟
    and a.饮料<>d.饮料
    and a.颜色<>d.颜色
    and a.宠物<>d.宠物and a.宠物<>e.宠物
    and a.国籍<>e.国籍
    and a.香烟<>e.香烟
    and a.饮料<>e.饮料
    and a.颜色<>e.颜色
    and a.宠物<>e.宠物and b.宠物<>c.宠物
    and b.国籍<>c.国籍
    and b.香烟<>c.香烟
    and b.饮料<>c.饮料
    and b.颜色<>c.颜色
    and b.宠物<>c.宠物and b.宠物<>d.宠物
    and b.国籍<>d.国籍
    and b.香烟<>d.香烟
    and b.饮料<>d.饮料
    and b.颜色<>d.颜色
    and b.宠物<>d.宠物and b.宠物<>e.宠物
    and b.国籍<>e.国籍
    and b.香烟<>e.香烟
    and b.饮料<>e.饮料
    and b.颜色<>e.颜色
    and b.宠物<>e.宠物and c.宠物<>d.宠物
    and c.国籍<>d.国籍
    and c.香烟<>d.香烟
    and c.饮料<>d.饮料
    and c.颜色<>d.颜色
    and c.宠物<>d.宠物and c.宠物<>e.宠物
    and c.国籍<>e.国籍
    and c.香烟<>e.香烟
    and c.饮料<>e.饮料
    and c.颜色<>e.颜色
    and c.宠物<>e.宠物and d.宠物<>e.宠物
    and d.国籍<>e.国籍
    and d.香烟<>e.香烟
    and d.饮料<>e.饮料
    and d.颜色<>e.颜色
    and d.宠物<>e.宠物
    /*
    and (a.颜色='绿色' and b.颜色='白色'
    or b.颜色='绿色' and c.颜色='白色'
    or c.颜色='绿色' and d.颜色='白色'
    or d.颜色='绿色' and e.颜色='白色')
    */
    and (b.宠物='猫' and (a.香烟='Blends' or c.香烟='Blends')
    or b.香烟='Blends' and (a.宠物='猫' or c.宠物='猫')
    or c.宠物='猫' and (b.香烟='Blends' or d.香烟='Blends')
    or c.香烟='Blends' and (b.宠物='猫' or d.宠物='猫')
    or d.宠物='猫' and (c.香烟='Blends' or e.香烟='Blends')
    or d.香烟='Blends' and (c.宠物='猫' or e.宠物='猫')
    )and (b.宠物='马' and (a.香烟='Dunhill' or c.香烟='Dunhill')
    or b.香烟='Dunhill' and (a.宠物='马' or c.宠物='马')
    or c.宠物='马' and (b.香烟='Dunhill' or d.香烟='Dunhill')
    or c.香烟='Dunhill' and (b.宠物='马' or d.宠物='马')
    or d.宠物='马' and (c.香烟='Dunhill' or e.香烟='Dunhill')
    or d.香烟='Dunhill' and (c.宠物='马' or e.宠物='马')
    )and (b.国籍='挪威' and (a.颜色='蓝色' or c.颜色='蓝色')
    or b.颜色='蓝色' and (a.国籍='挪威' or c.国籍='挪威')
    or c.国籍='挪威' and (b.颜色='蓝色' or d.颜色='蓝色')
    or c.颜色='蓝色' and (b.国籍='挪威' or d.国籍='挪威')
    or d.国籍='挪威' and (c.颜色='蓝色' or e.颜色='蓝色')
    or d.颜色='蓝色' and (c.国籍='挪威' or e.国籍='挪威')
    )and (b.饮料='水' and (a.香烟='Blends' or c.香烟='Blends')
    or b.香烟='Blends' and (a.饮料='水' or c.饮料='水')
    or c.饮料='水' and (b.香烟='Blends' or d.香烟='Blends')
    or c.香烟='Blends' and (b.饮料='水' or d.饮料='水')
    or d.饮料='水' and (c.香烟='Blends' or e.香烟='Blends')
    or d.香烟='Blends' and (c.饮料='水' or e.饮料='水')
    )and ( a.国籍='挪威' or e.国籍='挪威')
    and (
    (a.颜色='绿色' and b.颜色='白色'
    or b.颜色='绿色' and c.颜色='白色'
    or c.颜色='绿色' and d.颜色='白色'
    or d.颜色='绿色' and e.颜色='白色')
    or
    (e.颜色='绿色' and d.颜色='白色'
    or d.颜色='绿色' and c.颜色='白色'
    or c.颜色='绿色' and b.颜色='白色'
    or b.颜色='绿色' and a.颜色='白色')

      

  30.   


    --结果
    Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   Num         颜色                   国籍                   饮料                   香烟                   宠物                   
    ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- -------------------- -------------------- -------------------- -------------------- -------------------- 
    1           白色                   瑞典                   啤酒                   Blue Master          狗                    2           绿色                   德国                   咖啡                   Prince               鱼                    3           红色                   英国                   牛奶                   Pall Mall            鸟                    4           蓝色                   丹麦                   茶                    Blends               马                    5           黄色                   挪威                   水                    Dunhill              猫
    1           黄色                   挪威                   水                    Dunhill              猫                    2           蓝色                   丹麦                   茶                    Blends               马                    3           红色                   英国                   牛奶                   Pall Mall            鸟                    4           绿色                   德国                   咖啡                   Prince               鱼                    5           白色                   瑞典                   啤酒                   Blue Master          狗
    1           黄色                   挪威                   水                    Dunhill              猫                    2           蓝色                   丹麦                   茶                    Blends               马                    3           红色                   英国                   牛奶                   Pall Mall            鸟                    4           白色                   瑞典                   啤酒                   Blue Master          狗                    5           绿色                   德国                   咖啡                   Prince               鱼
    1           绿色                   德国                   咖啡                   Prince               鱼                    2           白色                   瑞典                   啤酒                   Blue Master          狗                    3           红色                   英国                   牛奶                   Pall Mall            鸟                    4           蓝色                   丹麦                   茶                    Blends               马                    5           黄色                   挪威                   水                    Dunhill              猫(所影响的行数为 4 行)
    (所影响的行数为 2 行)--结论:答案是唯一的,德国人养鱼
    --关键不同还是  
    --4、绿色房子在白色房子左面
    --的理解,如果最左边不一定是第一,左面的意思也不是隔壁
    --那说这个条件是否等于没说?
    --这是我的理解
      

  31.   

    建议将新秀们的30分给予:
    唯一给出脚本的cxmcxm(小陈)同学,10分。
    liangCK(小梁)同学积极参与, springzfc, winjay84(绿绿的蛋挞), parss(往事如云) 分别以Script以外的方式给出答案
    建议分别给予5分以资鼓励请星星们评议。
      

  32.   

    星星们的酬劳:
    * happyflystone(无枪狙击手) 10 + 5 (维持持续的声音)
    * fa_ge(鶴嘯九天) 10
    * jinjazz(近身剪) 10 - 5 (犯规处罚)
    * dobear_0922(do熊) 10
    * fcuandy(人, 无完人;学, 无止境) 10
    * Haiwer(海阔天空) 10 - 5 (犯规处罚) + 10 (详细答案)如果没有其他提议,明日将依次结算闭帖。
      

  33.   

    本帖最后由 cxmcxm 于 2007-12-26 22:27:56 编辑