日期:2014-05-18  浏览次数:20448 次

你厉害吗,来过5关试试?(挑战你的智商!)
http://www.sostart.com/article/view.php/765

每个优秀通过sql语句来计算最终得完成路径



比如第四关的一种解法



规则:
在一个棋盘中棋子的路线同象棋中的马,走"日字"

目标:
从任意一个点起跳,经过每个格子一次,最终能够回到源点。

棋盘坐标:



原理:
通过递归,在15步之后(一共14个格子,起始点经过2次)回到起始点

算法:

SQL code

--第四关:跳马

declare @t table(p varchar(max),x int,y int)
insert into @t 
select 'p11',1,1 union 
select 'p12',1,2 union 
select 'p13',1,3 union 
select 'p14',1,4 union 
select 'p21',2,1 union 
select 'p22',2,2 union 
select 'p23',2,3 union 
select 'p24',2,4 union 
select 'p31',3,1 union 
select 'p32',3,2 union 
select 'p33',3,3 union 
select 'p34',3,4 union 
select 'p42',4,2 union 
select 'p43',4,3 

;with t(pstart,p,c,x,y) as
(
    select  p,p,1,x,y from @t
        union all
    select t.pstart,t.p+'->'+t_next.p,c+1,t_next.x,t_next.y from @t t_next,t where 
        (
            (abs(t_next.x-t.x)=1 and abs(t_next.y-t.y)=2) or
            (abs(t_next.x-t.x)=2 and abs(t_next.y-t.y)=1) )
            and (CHARINDEX(t_next.p,t.p)=0 or (c=14 and t_next.p=t.pstart))
)
select p from t  where c=15


结果:

每个格子都可以作为起始点,各自有8种解法,一共112种组合。不借助外力能快速完成的人应该具有极高的智商或者及好的rp。








------解决方案--------------------
先占位.
------解决方案--------------------
站位编辑 明早再来看看 哈
------解决方案--------------------

------解决方案--------------------
哈哈,有意思,先收藏明天再看
------解决方案--------------------
刚才过了第一关
------解决方案--------------------
老大,俺是来的。
------解决方案--------------------
游戏不错
------解决方案--------------------
卡位置
------解决方案--------------------
逻辑性好强啊。
俺也占个位学习学习
------解决方案--------------------
为了接分来的
------解决方案--------------------
很有难度、、、、
------解决方案--------------------
看看啊,什么游戏啊!
------解决方案--------------------
看看啊,娱乐下
------解决方案--------------------
先占位~~~~
------解决方案--------------------
每天回帖即可获得10分可用分!小技巧:教您如何更快获得可用分

------解决方案--------------------
想想看...
------解决方案--------------------

全过了,但不知SQL解法!
------解决方案--------------------

------解决方案--------------------
玩人的游戏
------解决方案--------------------

------解决方案--------------------
占位,回去再研究。。。
------解决方案--------------------
好~~~~~
------解决方案--------------------