楼主: newkid

[每日一题] PUZZLEUP 2015

[复制链接]
论坛徽章:
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
91#
发表于 2015-8-13 10:34 | 只看该作者
本帖最后由 〇〇 于 2015-8-13 10:42 编辑
lastwinner 发表于 2015-8-13 10:27
看89#,十来毫秒出
我看错了>800是调试语句

使用道具 举报

回复
论坛徽章:
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
92#
发表于 2015-8-13 10:43 | 只看该作者
本帖最后由 lastwinner 于 2015-8-13 10:44 编辑
〇〇 发表于 2015-8-13 10:34
>800有什么根据
说不定有个10位的呢
实际上最后是去掉800的限制,一开始只是为调试而做的限制
并且,代码里是注释掉大于800的限制了啊

使用道具 举报

回复
论坛徽章:
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
93#
发表于 2015-8-13 10:59 | 只看该作者
lastwinner 发表于 2015-8-13 10:43
实际上最后是去掉800的限制,一开始只是为调试而做的限制
并且,代码里是注释掉大于800的限制了啊

每层这么少
select count(*)cnt,lvl from w group by lvl order by 2;
  2    3    4    5    6    7    8  
       CNT        LVL
---------- ----------
      1108          2
      1870          3
      2448          4
      1378          5
       504          6
        47          7

已选择6行。

使用道具 举报

回复
论坛徽章:
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
94#
发表于 2015-8-13 11:05 | 只看该作者
〇〇 发表于 2015-8-13 10:59
每层这么少
select count(*)cnt,lvl from w group by lvl order by 2;
  2    3    4    5    6    7   ...

我的前4层也很快,后面就不行了
SQL> with t as(select level-1 l from dual connect by level<=10)
,t3 as(select distinct a.l||b.l||c.l l from t a,t b,t c where a.l*a.l/2>b.l*c.l
and a.l<>b.l and b.l<>c.l and c.l<>a.l)
,t4 as(select distinct a.l||substr(b.l,-1) l from t3 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t5 as(select distinct a.l||substr(b.l,-1) l from t4 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t6 as(select distinct a.l||substr(b.l,-1) l from t5 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
select (select count(*) from t3)c3,
(select count(*) from t4)c4,
(select count(*) from t5)c5,
(select count(*) from t6)c6 from dual;  2    3    4    5    6    7    8    9   10   11   12   13  

        C3         C4         C5         C6
---------- ---------- ---------- ----------
       342       1108       1870       2426

SQL> set timi on
SQL> /

        C3         C4         C5         C6
---------- ---------- ---------- ----------
       342       1108       1870       2426

已用时间:  00: 00: 00.02

使用道具 举报

回复
论坛徽章:
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
95#
发表于 2015-8-13 11:08 | 只看该作者
〇〇 发表于 2015-8-13 11:05
我的前4层也很快,后面就不行了
SQL> with t as(select level-1 l from dual connect by levelb.l*c.l
a ...

奇诡 这么写10层都很快
SQL> with t as(select level-1 l from dual connect by level<=10)
,t3 as(select distinct a.l||b.l||c.l l from t a,t b,t c where a.l*a.l/2>b.l*c.l
and a.l<>b.l and b.l<>c.l and c.l<>a.l)
,t4 as(select distinct a.l||substr(b.l,-1) l from t3 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t5 as(select distinct a.l||substr(b.l,-1) l from t4 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t6 as(select distinct a.l||substr(b.l,-1) l from t5 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t7 as(select distinct a.l||substr(b.l,-1) l from t6 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t8 as(select distinct a.l||substr(b.l,-1) l from t7 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t9 as(select distinct a.l||substr(b.l,-1) l from t8 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t10 as(select distinct a.l||substr(b.l,-1) l from t9 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
select (select count(*) from t3)c3,
(select count(*) from t4)c4,
(select count(*) from t5)c5,
(select count(*) from t6)c6,
(select count(*) from t7)c7,
(select count(*) from t8)c8,
(select count(*) from t9)c9
(select count(*) from t10)c10
from dual;  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26  
(select count(*) from t10)c10
*
第 25 行出现错误:
ORA-00923: 未找到要求的 FROM 关键字


已用时间:  00: 00: 00.00
SQL> 24
24* (select count(*) from t9)c9
SQL> a ,
24* (select count(*) from t9)c9,
SQL> /

        C3         C4         C5         C6         C7         C8         C9
---------- ---------- ---------- ---------- ---------- ---------- ----------
       C10
----------
       342       1108       1870       2426       1237        373         26
         0


已用时间:  00: 00: 00.06
SQL>

使用道具 举报

回复
论坛徽章:
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
96#
发表于 2015-8-13 11:17 | 只看该作者
〇〇 发表于 2015-8-13 11:08
奇诡 这么写10层都很快
SQL> with t as(select level-1 l from dual connect by levelb.l*c.l
and a.lb ...

经过一番改写,我的也毫秒出了,缺点是人工认为9位最长
with t as(select level-1 l from dual connect by level<=10)
,t3 as(select distinct a.l||b.l||c.l l from t a,t b,t c where a.l*a.l/2>b.l*c.l
and a.l<>b.l and b.l<>c.l and c.l<>a.l)
,t4 as(select distinct a.l||substr(b.l,-1) l from t3 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t5 as(select distinct a.l||substr(b.l,-1) l from t4 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t6 as(select distinct a.l||substr(b.l,-1) l from t5 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t7 as(select distinct a.l||substr(b.l,-1) l from t6 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t8 as(select distinct a.l||substr(b.l,-1) l from t7 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t9 as(select distinct a.l||substr(b.l,-1) l from t8 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t10 as(select distinct a.l||substr(b.l,-1) l from t9 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,taiqiguaile as(select (select count(*) from t3)c3,
(select count(*) from t4)c4,
(select count(*) from t5)c5,
(select count(*) from t6)c6,
(select count(*) from t7)c7,
(select count(*) from t8)c8,
(select count(*) from t9)c9,
(select count(*) from t10)c10 ,t9.l
from dual,t9)
select max(l) from taiqiguaile;

使用道具 举报

回复
论坛徽章:
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
97#
发表于 2015-8-13 12:01 | 只看该作者
本帖最后由 solomon_007 于 2015-8-13 12:02 编辑
lastwinner 发表于 2015-8-13 09:32
先求出所有的符合条件的3位数
然后做connect by,尽可能的以9开头,尽可能的以较大的数衔接在右边(左边 ...
根据你的思路:

SQL> with t as (select rownum-1 n from dual connect by rownum<=10),
  2       s as (select a.n||b.n||c.n v
  3               from t a, t b, t c
  4              where a.n <> b.n
  5                and b.n <> c.n
  6                and a.n <> c.n
  7                and a.n*a.n > 2*b.n*c.n),
  8       r as (
  9   select level lvl,v,replace(sys_connect_by_path(decode(level,1,v,substr(v,length(v),1)),','),',','') str
10     from s
11    where level <=8
12  connect by nocycle prior substr(v,2) = substr(v,1,2))
13  select max(to_number(str))
14    from r
15   where instr(substr(str,1,length(str)-1),substr(v,length(v),1)) = 0
16  /
MAX(TO_NUMBER(STR))
-------------------
          985432107

使用道具 举报

回复
论坛徽章:
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
98#
发表于 2015-8-13 12:09 | 只看该作者
〇〇 发表于 2015-8-13 11:17
经过一番改写,我的也毫秒出了,缺点是人工认为9位最长
with t as(select level-1 l from dual connect by ...

改好了
with t as(select level-1 l from dual connect by level<=10)
,t3 as(select distinct a.l||b.l||c.l l from t a,t b,t c where a.l*a.l/2>b.l*c.l
and a.l<>b.l and b.l<>c.l and c.l<>a.l)
,t4 as(select distinct a.l||substr(b.l,-1) l from t3 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t5 as(select distinct a.l||substr(b.l,-1) l from t4 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t6 as(select distinct a.l||substr(b.l,-1) l from t5 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t7 as(select distinct a.l||substr(b.l,-1) l from t6 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t8 as(select distinct a.l||substr(b.l,-1) l from t7 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t9 as(select distinct a.l||substr(b.l,-1) l from t8 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t10 as(select distinct a.l||substr(b.l,-1) l from t9 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,taihaole as(select nvl((select max(to_number(l)) from t3),0)c3,
nvl((select max(to_number(l)) from t4),0)c4,
nvl((select max(to_number(l)) from t5),0)c5,
nvl((select max(to_number(l)) from t6),0)c6,
nvl((select max(to_number(l)) from t7),0)c7,
nvl((select max(to_number(l)) from t8),0)c8,
nvl((select max(to_number(l)) from t9),0)c9,
nvl((select max(to_number(l)) from t10),0)c10
from dual)
select greatest(c3,c4,c5,c6,c7,c8,c9,c10) from taihaole;

使用道具 举报

回复
论坛徽章:
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
99#
发表于 2015-8-13 12:11 | 只看该作者
solomon_007 发表于 2015-8-13 12:01
根据你的思路:

SQL> with t as (select rownum-1 n from dual connect by rownum 2*b.n*c.n),

和89楼很像

使用道具 举报

回复
论坛徽章:
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#
发表于 2015-8-13 12:24 | 只看该作者
〇〇 发表于 2015-8-13 12:11
和89楼很像

  一样的

使用道具 举报

回复

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

本版积分规则 发表回复

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