楼主: newkid

[每日一题] puzzleup 2018

[复制链接]
论坛徽章:
2
紫蜘蛛
日期:2018-08-24 21:46:44玉兔
日期:2018-09-07 22:04:20
91#
发表于 2018-9-6 11:26 | 只看该作者
66240

with tab1 as (
select t1.a || t2.a || t3.a || t4.a || t5.a a
  from (select chr(64 + level) a from dual connect by level <= 5) t1,
       (select chr(64 + level) a from dual connect by level <= 5) t2,
       (select chr(64 + level) a from dual connect by level <= 5) t3,
       (select chr(64 + level) a from dual connect by level <= 5) t4,
       (select chr(64 + level) a from dual connect by level <= 5) t5
where 1 = 1
   and not regexp_like(t1.a || t2.a || t3.a || t4.a || t5.a, '(\w)[^\1]{0,}\1')
)
select count(1)
from tab1 t1, tab1 t2, tab1 t3
where 1 = 1
  and not regexp_like(substr(t1.a, 1, 1) || substr(t2.a, 1, 1) || substr(t3.a, 1, 1), '(\w)[^\1]{0,}\1')
  and not regexp_like(substr(t1.a, 2, 1) || substr(t2.a, 2, 1) || substr(t3.a, 2, 1), '(\w)[^\1]{0,}\1')
  and not regexp_like(substr(t1.a, 3, 1) || substr(t2.a, 3, 1) || substr(t3.a, 3, 1), '(\w)[^\1]{0,}\1')
  and not regexp_like(substr(t1.a, 4, 1) || substr(t2.a, 4, 1) || substr(t3.a, 4, 1), '(\w)[^\1]{0,}\1')
  and not regexp_like(substr(t1.a, 5, 1) || substr(t2.a, 5, 1) || substr(t3.a, 5, 1), '(\w)[^\1]{0,}\1')
;

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
92#
发表于 2018-9-6 11:42 | 只看该作者
6#
SQL>
SQL> with t as (select chr(64 + level) n from dual connect by level <= 5),
  2       s(lvl,str) as (select 1,n from t
  3                       union all
  4                      select lvl + 1,
  5                             s.str||t.n
  6                        from s,t
  7                       where lvl < 5
  8                         and instr(s.str,t.n)=0
  9                      )
10   select count(a.str||b.str||c.str)
11     from (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z, substr(str,4,1) u,substr(str,5,1) v from s where lvl = 5) a,
12          (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z, substr(str,4,1) u,substr(str,5,1) v from s where lvl = 5) b,
13          (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z, substr(str,4,1) u,substr(str,5,1) v from s where lvl = 5) c
14    where a.x <> b.x and b.x <> c.x and c.x <> a.x
15      and a.y <> b.y and b.y <> c.y and c.y <> a.y
16      and a.z <> b.z and b.z <> c.z and c.z <> a.z
17      and a.u <> b.u and b.u <> c.u and c.u <> a.u
18      and a.v <> b.v and b.v <> c.v and c.v <> a.v
19  /
COUNT(A.STR||B.STR||C.STR)
--------------------------
                     66240

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
93#
发表于 2018-9-6 11:44 | 只看该作者
3 的情形:

SQL> with t as (select chr(64 + level) n from dual connect by level <= 3),
  2       s(lvl,str) as (select 1,n from t
  3                       union all
  4                      select lvl + 1,
  5                             s.str||t.n
  6                        from s,t
  7                       where lvl < 3
  8                         and instr(s.str,t.n)=0
  9                      )
10       select count(a.str||b.str||c.str)
11         from (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z from s where lvl = 3) a,
12              (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z from s where lvl = 3) b,
13              (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z from s where lvl = 3) c
14        where a.x <> b.x and b.x <> c.x and c.x <> a.x
15          and a.y <> b.y and b.y <> c.y and c.y <> a.y
16          and a.z <> b.z and b.z <> c.z and c.z <> a.z
17  /
COUNT(A.STR||B.STR||C.STR)
--------------------------
                        12

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
94#
发表于 2018-9-6 11:45 | 只看该作者
3。。。


SQL> with t as (select chr(64 + level) n from dual connect by level <= 3),
  2       s as (select t1.n X, t2.n Y, t3.n Z
  3                from t t1, t t2, t t3
  4               where t1.n <> t2.n
  5                 and t2.n <> t3.n
  6                 and t3.n <> t1.n )
  7  select s1.x x1,s1.y y1,s1.z z1,
  8         s2.x x2,s2.y y2,s2.z z2,
  9         s3.x x3,s3.y y3,s3.z z3
10    from s s1,s s2,s s3
11   where s1.z <> s2.z and s2.z <> s3.z and s3.z <> s1.z
12     and s1.y <> s2.y and s2.y <> s3.y and s3.y <> s1.y
13     and s1.x <> s2.x and s2.x <> s3.x and s3.x <> s1.x
14  /
X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3
-- -- -- -- -- -- -- -- --
A  B  C  B  C  A  C  A  B
A  B  C  C  A  B  B  C  A
A  C  B  B  A  C  C  B  A
A  C  B  C  B  A  B  A  C
B  A  C  A  C  B  C  B  A
B  A  C  C  B  A  A  C  B
B  C  A  A  B  C  C  A  B
B  C  A  C  A  B  A  B  C
C  A  B  A  B  C  B  C  A
C  A  B  B  C  A  A  B  C
C  B  A  A  C  B  B  A  C
C  B  A  B  A  C  A  C  B
12 rows selected

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
95#
发表于 2018-9-6 11:47 | 只看该作者
6#  
发了怎么没看到,再发一下

SQL> with t as (select chr(64 + level) n from dual connect by level <= 5),
  2       s(lvl,str) as (select 1,n from t
  3                       union all
  4                      select lvl + 1,
  5                             s.str||t.n
  6                        from s,t
  7                       where lvl < 5
  8                         and instr(s.str,t.n)=0
  9                      )
10   select count(a.str||b.str||c.str)
11     from (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z, substr(str,4,1) u,substr(str,5,1) v from s where lvl = 5) a,
12          (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z, substr(str,4,1) u,substr(str,5,1) v from s where lvl = 5) b,
13          (select str ,substr(str,1,1) x,substr(str,2,1) y,substr(str,3,1) z, substr(str,4,1) u,substr(str,5,1) v from s where lvl = 5) c
14    where a.x <> b.x and b.x <> c.x and c.x <> a.x
15      and a.y <> b.y and b.y <> c.y and c.y <> a.y
16      and a.z <> b.z and b.z <> c.z and c.z <> a.z
17      and a.u <> b.u and b.u <> c.u and c.u <> a.u
18      and a.v <> b.v and b.v <> c.v and c.v <> a.v
19  /
COUNT(A.STR||B.STR||C.STR)
--------------------------
                     66240

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
96#
发表于 2018-9-6 16:05 | 只看该作者
化简一下:

SQL> with t as (select chr(64 + level) n from dual connect by level <= 5),
  2        s(lvl,str) as (select 1,n from t
  3                        union all
  4                       select lvl + 1,
  5                              s.str||t.n
  6                         from s,t
  7                        where lvl < 5
  8                          and instr(s.str,t.n)=0),
  9         r as (select str,
10                      substr(str,1,1) x,
11                      substr(str,2,1) y,
12                      substr(str,3,1) z,
13                      substr(str,4,1) u,
14                      substr(str,5,1) v
15                 from s
16                where lvl = 5)
17    select count(a.str||b.str||c.str)
18      from r a,r b, r c
19     where a.x <> b.x and b.x <> c.x and c.x <> a.x
20       and a.y <> b.y and b.y <> c.y and c.y <> a.y
21       and a.z <> b.z and b.z <> c.z and c.z <> a.z
22       and a.u <> b.u and b.u <> c.u and c.u <> a.u
23       and a.v <> b.v and b.v <> c.v and c.v <> a.v
24  /
COUNT(A.STR||B.STR||C.STR)
--------------------------
                     66240

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
97#
 楼主| 发表于 2018-9-6 21:43 | 只看该作者


再帮你化简一下:
with t as (select chr(64 + level) n from dual connect by level <= 5),
  s as (select replace(sys_connect_by_path(n,','),',') as str from t where level=5 connect by nocycle n<>prior n),
   r as (select str,
               substr(str,1,1) x,
               substr(str,2,1) y,
               substr(str,3,1) z,
               substr(str,4,1) u,
               substr(str,5,1) v
          from s)
  select count(a.str||b.str||c.str)
    from r a,r b, r c
   where a.x <> b.x and b.x <> c.x and c.x <> a.x
     and a.y <> b.y and b.y <> c.y and c.y <> a.y
     and a.z <> b.z and b.z <> c.z and c.z <> a.z
     and a.u <> b.u and b.u <> c.u and c.u <> a.u
     and a.v <> b.v and b.v <> c.v and c.v <> a.v
/

COUNT(A.STR||B.STR||C.STR)
--------------------------
                     66240   
                     


我的写法:
---- 每个数占用五个二进制位,其中有且仅有一位为1, 表示这个数在排列中所处的位置
WITH t(cnt,s,p) AS (
SELECT 1,CAST(LEVEL AS VARCHAR2(10)),POWER(2,(LEVEL-1)*5) FROM DUAL CONNECT BY LEVEL<=5
UNION ALL
SELECT cnt+1,s||n
      ,p+POWER(2,(n-1)*5+cnt)
  FROM t,(SELECT LEVEL n FROM DUAL CONNECT BY LEVEL<=5)
WHERE INSTR(s,n)=0 AND cnt<5
)
,b AS (SELECT * FROM t WHERE cnt=5)
SELECT COUNT(*)
  FROM b b1,b b2,b b3
WHERE BITAND(b1.p,b2.p)=0
      AND BITAND(b1.p,b3.p)=0
      AND BITAND(b2.p,b3.p)=0
;


COUNT(*)
---------
    66240


给你们一人发一个章,请点菜。

使用道具 举报

回复
论坛徽章:
8
玉兔
日期:2015-11-16 10:18:00铁扇公主
日期:2015-10-27 21:47:42九尾狐狸
日期:2015-12-11 22:31:15
98#
发表于 2018-9-7 09:30 | 只看该作者
绝对的暴力,和MMA比简洁,哼


使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
99#
发表于 2018-9-7 09:34 | 只看该作者
lugionline 发表于 2018-9-7 09:30
绝对的暴力,和MMA比简洁,哼

  大神,NIUBILITY!!

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
100#
发表于 2018-9-7 09:37 | 只看该作者
newkid 发表于 2018-9-6 21:43
再帮你化简一下:
with t as (select chr(64 + level) n from dual connect by level

bitand 很优雅 !

你的秀才很多,要给的话,给个秀才吧

使用道具 举报

回复

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

本版积分规则 发表回复

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