楼主: 〇〇

[精华] Puzzleup 2010 比赛快开始了,大家用SQL解答啊

[复制链接]
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
121#
发表于 2010-9-9 09:10 | 只看该作者

回复 #119 newkid 的帖子

AND n1.n NOT IN (n2.n+1,n2.n-1) AND n2.n NOT IN (n3.n+1,n3.n-1)
       AND n4.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n6.n+1,n6.n-1)
       AND n7.n NOT IN (n8.n+1,n8.n-1) AND n8.n NOT IN (n9.n+1,n9.n-1)
       AND n1.n NOT IN (n4.n+1,n4.n-1) AND n4.n NOT IN (n7.n+1,n7.n-1)
       AND n2.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n8.n+1,n8.n-1)
       AND n3.n NOT IN (n6.n+1,n6.n-1) AND n6.n NOT IN (n9.n+1,n9.n-1)

用ABS感觉会更好,而且更简洁

对于
ABC
DEF
GHI

只需要关注BDEFH
abs(e-b)>1 and abs(e-d)>1 and abs(e-f)>1 and abs(e-h>1
and abs(b-a)>1 and abs(b-c)>1
and abs(d-a)>1 and abs(d-g)>1
and abs(h-g)>1 and abs(h-i)>1
and abs(f-c)>1 and abs(f-i)>1
跟你的这12个not in是等价的,你是从左到右从上到下,看明白了也就好理解了

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
122#
 楼主| 发表于 2010-9-9 09:19 | 只看该作者
按照对称原理,把119楼装修了下

WITH
n AS (SELECT ROWNUM-1 n FROM DUAL CONNECT BY ROWNUM<=10)
select * from(
SELECT path ,m1*m2*m3 m FROM (
SELECT n1.n||n2.n||n3.n||n4.n||n5.n||n6.n||n7.n||n8.n||n9.n path
      ,REPLACE(n1.n||n2.n||n3.n,GREATEST(n1.n,n2.n,n3.n))m1
       ,REPLACE(n4.n||n5.n||n6.n,GREATEST(n4.n,n5.n,n6.n))m2
       ,REPLACE(n7.n||n8.n||n9.n,GREATEST(n7.n,n8.n,n9.n)) m3
  FROM n n1,n n2,n n3,n n4,n n5,n n6,n n7,n n8,n n9
WHERE n1.n NOT IN (n2.n,n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n2.n NOT IN (n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n3.n NOT IN (n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n4.n NOT IN (n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n5.n NOT IN (n6.n,n7.n,n8.n,n9.n)
       AND n6.n NOT IN (n7.n,n8.n,n9.n)
       AND n7.n NOT IN (n8.n,n9.n)
       AND n8.n<>n9.n
       AND n1.n NOT IN (n2.n+1,n2.n-1) AND n2.n NOT IN (n3.n+1,n3.n-1)
       AND n4.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n6.n+1,n6.n-1)
       AND n7.n NOT IN (n8.n+1,n8.n-1) AND n8.n NOT IN (n9.n+1,n9.n-1)
       AND n1.n NOT IN (n4.n+1,n4.n-1) AND n4.n NOT IN (n7.n+1,n7.n-1)
       AND n2.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n8.n+1,n8.n-1)
       AND n3.n NOT IN (n6.n+1,n6.n-1) AND n6.n NOT IN (n9.n+1,n9.n-1)
)
where substr(m1,1,1)>substr(m1,2,1) and
substr(m2,1,1)>substr(m2,2,1) and
substr(m3,1,1)>substr(m3,2,1)

ORDER BY 2 DESC)
WHERE ROWNUM=1;

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
123#
发表于 2010-9-9 09:24 | 只看该作者
原帖由 〇〇 于 10-9-9 09:05 发表

越接近正方形,面积越大


这是周长一定情况下

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
124#
发表于 2010-9-9 09:28 | 只看该作者
原帖由 〇〇 于 10-9-9 09:19 发表
按照对称原理,把119楼装修了下

WITH
n AS (SELECT ROWNUM-1 n FROM DUAL CONNECT BY ROWNUMsubstr(m1,2,1) and
substr(m2,1,1)>substr(m2,2,1) and
substr(m3,1,1)>substr(m3,2,1)
ORDER BY 2 DESC)
WHERE ROWNUM=1;


这里不大适合用对称
比如
783
561
是满足邻居不连续的题设的
但按你这么一过滤,就成了
783
651
才满足你的条件,然而这又违反了邻居不连续的题设

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
125#
 楼主| 发表于 2010-9-9 09:36 | 只看该作者

回复 #124 lastwinner 的帖子


abc
def
ghi

cba
fed
ihg
是对称的
划掉最大值后也是对称的
这时,某一个行42,一定比24大,但确实无法保证3行的顺序都是一样的...

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
126#
 楼主| 发表于 2010-9-9 15:48 | 只看该作者
花花的速度和newkid是一样的..

n AS (SELECT ROWNUM-1 n FROM DUAL CONNECT BY ROWNUM<=10)
select * from(
SELECT path ,m1*m2*m3 m FROM (
SELECT n1.n||n2.n||n3.n||n4.n||n5.n||n6.n||n7.n||n8.n||n9.n path
      ,REPLACE(n1.n||n2.n||n3.n,GREATEST(n1.n,n2.n,n3.n))m1
       ,REPLACE(n4.n||n5.n||n6.n,GREATEST(n4.n,n5.n,n6.n))m2
       ,REPLACE(n7.n||n8.n||n9.n,GREATEST(n7.n,n8.n,n9.n)) m3
  FROM n n1,n n2,n n3,n n4,n n5,n n6,n n7,n n8,n n9
WHERE n1.n NOT IN (n2.n,n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n2.n NOT IN (n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n3.n NOT IN (n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n4.n NOT IN (n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n5.n NOT IN (n6.n,n7.n,n8.n,n9.n)
       AND n6.n NOT IN (n7.n,n8.n,n9.n)
       AND n7.n NOT IN (n8.n,n9.n)
       AND /*n8.n<>n9.n
       AND n1.n NOT IN (n2.n+1,n2.n-1) AND n2.n NOT IN (n3.n+1,n3.n-1)
       AND n4.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n6.n+1,n6.n-1)
       AND n7.n NOT IN (n8.n+1,n8.n-1) AND n8.n NOT IN (n9.n+1,n9.n-1)
       AND n1.n NOT IN (n4.n+1,n4.n-1) AND n4.n NOT IN (n7.n+1,n7.n-1)
       AND n2.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n8.n+1,n8.n-1)
       AND n3.n NOT IN (n6.n+1,n6.n-1) AND n6.n NOT IN (n9.n+1,n9.n-1)*/
abs(n5.n-n2.n)>1 and abs(n5.n-n4.n)>1 and abs(n5.n-n6.n)>1 and abs(n5.n-n8.n)>1
and abs(n2.n-n1.n)>1 and abs(n2.n-n3.n)>1
and abs(n4.n-n1.n)>1 and abs(n4.n-n7.n)>1
and abs(n8.n-n7.n)>1 and abs(n8.n-n9.n)>1
and abs(n6.n-n3.n)>1 and abs(n6.n-n9.n)>1      
)
where substr(m1,1,1)>substr(m1,2,1) and
substr(m2,1,1)>substr(m2,2,1) and
substr(m3,1,1)>substr(m3,2,1)
ORDER BY 2 DESC)
WHERE ROWNUM=1;

PATH
------------------------
         M
----------
637809425
    211680


已用时间:  00: 00: 02.95

[ 本帖最后由 〇〇 于 2010-9-9 15:52 编辑 ]

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
127#
 楼主| 发表于 2010-9-9 17:05 | 只看该作者
我的写法怎么会多

with t as(select a from (select to_char(level-1,'fm999') a from dual connect by level<=1000)
where substr(a,1,1)not in(substr(a,2,1) ,substr(a,3,1))
and substr(a,2,1)<>substr(a,3,1)
and substr(a,1,1)-substr(a,2,1) not in(-1,1)
and substr(a,3,1)-substr(a,2,1) not in(-1,1)
)
,t2 as(select a.a||b.a||c.a p
,REPLACE(a.a,GREATEST(substr(a.a,1,1),substr(a.a,2,1),substr(a.a,3,1)))m1
       ,REPLACE(b.a,GREATEST(substr(b.a,1,1),substr(b.a,2,1),substr(b.a,3,1)))m2
       ,REPLACE(c.a,GREATEST(substr(c.a,1,1),substr(c.a,2,1),substr(c.a,3,1))) m3
from t a,t b, t c
where a.a not in(b.a,c.a) and b.a<>c.a
and length(translate('$1234567890','$'||b.a||a.a,'$'))=5
and length(translate('$1234567890','$'||b.a||c.a,'$'))=5
and length(translate('$1234567890','$'||c.a||a.a,'$'))=5
and substr(a.a,1,1)-substr(b.a,1,1) not in (-1,1)
and substr(c.a,1,1)-substr(b.a,1,1) not in (-1,1)
and substr(a.a,2,1)-substr(b.a,2,1) not in (-1,1)
and substr(c.a,2,1)-substr(b.a,2,1) not in (-1,1)
and substr(a.a,3,1)-substr(b.a,3,1) not in (-1,1)
and substr(c.a,3,1)-substr(b.a,3,1) not in (-1,1)
)
select count(*) from t2;

  COUNT(*)
----------
    125432

已用时间:  00: 00: 26.84



WITH
n AS (SELECT ROWNUM-1 n FROM DUAL CONNECT BY ROWNUM<=10)
select count(*) from(
SELECT path ,m1*m2*m3 m FROM (
SELECT n1.n||n2.n||n3.n||n4.n||n5.n||n6.n||n7.n||n8.n||n9.n path
      ,REPLACE(n1.n||n2.n||n3.n,GREATEST(n1.n,n2.n,n3.n))m1
       ,REPLACE(n4.n||n5.n||n6.n,GREATEST(n4.n,n5.n,n6.n))m2
       ,REPLACE(n7.n||n8.n||n9.n,GREATEST(n7.n,n8.n,n9.n)) m3
  FROM n n1,n n2,n n3,n n4,n n5,n n6,n n7,n n8,n n9
WHERE n1.n NOT IN (n2.n,n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n2.n NOT IN (n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n3.n NOT IN (n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n4.n NOT IN (n5.n,n6.n,n7.n,n8.n,n9.n)
       AND n5.n NOT IN (n6.n,n7.n,n8.n,n9.n)
       AND n6.n NOT IN (n7.n,n8.n,n9.n)
       AND n7.n NOT IN (n8.n,n9.n)
       AND /*n8.n<>n9.n
       AND n1.n NOT IN (n2.n+1,n2.n-1) AND n2.n NOT IN (n3.n+1,n3.n-1)
       AND n4.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n6.n+1,n6.n-1)
       AND n7.n NOT IN (n8.n+1,n8.n-1) AND n8.n NOT IN (n9.n+1,n9.n-1)
       AND n1.n NOT IN (n4.n+1,n4.n-1) AND n4.n NOT IN (n7.n+1,n7.n-1)
       AND n2.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n8.n+1,n8.n-1)
       AND n3.n NOT IN (n6.n+1,n6.n-1) AND n6.n NOT IN (n9.n+1,n9.n-1)*/
abs(n5.n-n2.n)>1 and abs(n5.n-n4.n)>1 and abs(n5.n-n6.n)>1 and abs(n5.n-n8.n)>1
and abs(n2.n-n1.n)>1 and abs(n2.n-n3.n)>1
and abs(n4.n-n1.n)>1 and abs(n4.n-n7.n)>1
and abs(n8.n-n7.n)>1 and abs(n8.n-n9.n)>1
and abs(n6.n-n3.n)>1 and abs(n6.n-n9.n)>1
)
where substr(m1,1,1)>substr(m1,2,1) and
substr(m2,1,1)>substr(m2,2,1) and
substr(m3,1,1)>substr(m3,2,1)
)
;

NT(*)
-----
18796

时间:  00: 00: 02.70

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
128#
 楼主| 发表于 2010-9-9 17:07 | 只看该作者
WITH
n AS (SELECT ROWNUM-1 n FROM DUAL CONNECT BY ROWNUM<=10)
select count(*) from(
SELECT path ,m1*m2*m3 m FROM (
SELECT n1.n||n2.n||n3.n||n4.n||n5.n||n6.n||n7.n||n8.n||n9.n path
       ,REPLACE(n1.n||n2.n||n3.n,GREATEST(n1.n,n2.n,n3.n))m1
        ,REPLACE(n4.n||n5.n||n6.n,GREATEST(n4.n,n5.n,n6.n))m2
        ,REPLACE(n7.n||n8.n||n9.n,GREATEST(n7.n,n8.n,n9.n)) m3
   FROM n n1,n n2,n n3,n n4,n n5,n n6,n n7,n n8,n n9
WHERE n1.n NOT IN (n2.n,n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
        AND n2.n NOT IN (n3.n,n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
        AND n3.n NOT IN (n4.n,n5.n,n6.n,n7.n,n8.n,n9.n)
        AND n4.n NOT IN (n5.n,n6.n,n7.n,n8.n,n9.n)
        AND n5.n NOT IN (n6.n,n7.n,n8.n,n9.n)
        AND n6.n NOT IN (n7.n,n8.n,n9.n)
        AND n7.n NOT IN (n8.n,n9.n)
        AND /*n8.n<>n9.n
        AND n1.n NOT IN (n2.n+1,n2.n-1) AND n2.n NOT IN (n3.n+1,n3.n-1)
        AND n4.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n6.n+1,n6.n-1)
        AND n7.n NOT IN (n8.n+1,n8.n-1) AND n8.n NOT IN (n9.n+1,n9.n-1)
        AND n1.n NOT IN (n4.n+1,n4.n-1) AND n4.n NOT IN (n7.n+1,n7.n-1)
        AND n2.n NOT IN (n5.n+1,n5.n-1) AND n5.n NOT IN (n8.n+1,n8.n-1)
        AND n3.n NOT IN (n6.n+1,n6.n-1) AND n6.n NOT IN (n9.n+1,n9.n-1)*/
abs(n5.n-n2.n)>1 and abs(n5.n-n4.n)>1 and abs(n5.n-n6.n)>1 and abs(n5.n-n8.n)>1
and abs(n2.n-n1.n)>1 and abs(n2.n-n3.n)>1
and abs(n4.n-n1.n)>1 and abs(n4.n-n7.n)>1
and abs(n8.n-n7.n)>1 and abs(n8.n-n9.n)>1
and abs(n6.n-n3.n)>1 and abs(n6.n-n9.n)>1
)
);

UNT(*)
------
175952

时间:  00: 00: 03.26

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
129#
 楼主| 发表于 2010-9-9 18:40 | 只看该作者
substr看来不是问题

with t as(select a m,substr(a,1,1)+0 a,substr(a,2,1)+0 b,substr(a,3,1)+0 c
from (select to_char(level-1,'fm999') a from dual connect by level<=1000)
where substr(a,1,1)not in(substr(a,2,1) ,substr(a,3,1))
and substr(a,2,1)<>substr(a,3,1)
and substr(a,1,1)-substr(a,2,1) not in(-1,1)
and substr(a,3,1)-substr(a,2,1) not in(-1,1)
)
,t2 as(select a.m||b.m||c.m p
,REPLACE(a.m,GREATEST(a.a,a.b,a.c))m1
        ,REPLACE(b.a,GREATEST(b.a,b.b,b.c))m2
        ,REPLACE(c.a,GREATEST(c.a,c.b,c.c)) m3
from t a,t b, t c
where a.m not in(b.m,c.m) and b.m<>c.m
and length(translate('$1234567890','$'||b.m||a.m,'$'))=5
and length(translate('$1234567890','$'||b.m||c.m,'$'))=5
and length(translate('$1234567890','$'||c.m||a.m,'$'))=5
and length(translate('$1234567890','$'||a.m||b.m||c.m,'$'))=2
and a.a-b.a not in (-1,1)
and c.a-b.a not in (-1,1)
and a.b-b.b not in (-1,1)
and c.b-b.b not in (-1,1)
and a.c-b.c not in (-1,1)
and c.c-b.c not in (-1,1)
)
select count(*) from t2;

UNT(*)
------
125432

时间:  00: 00: 26.89

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
130#
 楼主| 发表于 2010-9-9 18:43 | 只看该作者
rule是我的好朋友
  with t as(select a m,substr(a,1,1)+0 a,substr(a,2,1)+0 b,substr(a,3,1)+0 c
  from (select to_char(level-1,'fm999') a from dual connect by level<=1000)
  where substr(a,1,1)not in(substr(a,2,1) ,substr(a,3,1))
  and substr(a,2,1)<>substr(a,3,1)
  and substr(a,1,1)-substr(a,2,1) not in(-1,1)
  and substr(a,3,1)-substr(a,2,1) not in(-1,1)
  )
  ,t2 as(select /*+rule*/a.m||b.m||c.m p
  ,REPLACE(a.m,GREATEST(a.a,a.b,a.c))m1
         ,REPLACE(b.a,GREATEST(b.a,b.b,b.c))m2
         ,REPLACE(c.a,GREATEST(c.a,c.b,c.c)) m3
  from t a,t b, t c
  where a.m not in(b.m,c.m) and b.m<>c.m
  and length(translate('$1234567890','$'||b.m||a.m,'$'))=5
  and length(translate('$1234567890','$'||b.m||c.m,'$'))=5
  and length(translate('$1234567890','$'||c.m||a.m,'$'))=5
  and length(translate('$1234567890','$'||a.m||b.m||c.m,'$'))=2
  and a.a-b.a not in (-1,1)
  and c.a-b.a not in (-1,1)
  and a.b-b.b not in (-1,1)
  and c.b-b.b not in (-1,1)
  and a.c-b.c not in (-1,1)
  and c.c-b.c not in (-1,1)
  )
  select count(*) from t2;

UNT(*)
------
125432

时间:  00: 00: 18.48

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表