楼主: newkid

[每日一题] puzzleup 2021

[复制链接]
论坛徽章:
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
141#
发表于 2021-10-7 18:58 | 只看该作者
--6*6+2    278s
with t(n,c,x,y) as (select level,chr(64+level),ceil(level/6),mod(level-1,6)+1 from dual connect by level<=6*6),
     s(lvl,n,
     --nlist,
     clist) as (select 1,
                               n,
                               --cast(n as varchar2(100)),
                               c
                          from t
                         union all
                        select lvl + 1,
                               b.n,
                               --nlist||','||b.n,
                               clist||','||b.c
                          from s,t b
                         where s.n < b.n                          
                           and (select greatest(sum(case when a.x = b.x then 1 end),
                                                sum(case when a.y = b.y then 1 end),
                                                sum(case when a.x-b.x = a.y-b.y then 1 end),
                                                sum(case when a.x-b.x = b.y-a.y then 1 end)
                                                )
                                  from t a
                                 where instr(clist||','||b.c,a.c)>0)<=2            
                            )
select max(lvl) from s
--
12

使用道具 举报

回复
论坛徽章:
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
142#
发表于 2021-10-7 19:15 来自手机 | 只看该作者
本帖最后由 〇〇 于 2021-10-7 19:38 编辑

6 6 2就是第一次sql大赛第二题中的例子

http://www.itpub.net/thread-1403356-1-1.html

使用道具 举报

回复
论坛徽章:
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
143#
发表于 2021-10-7 19:33 来自手机 | 只看该作者
每行最多2个时,最好结果就是每行都2个,因此前几行可以加b. n的限制条件为lv1和2在1-6之间,3和4在6-12之间

使用道具 举报

回复
论坛徽章:
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
144#
发表于 2021-10-7 19:35 来自手机 | 只看该作者
由于图形的对称性,lv1在1-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
145#
发表于 2021-10-7 20:18 来自手机 | 只看该作者
加了以上约束条件6 6 2用时5秒

使用道具 举报

回复
论坛徽章:
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
146#
发表于 2021-10-7 20:26 来自手机 | 只看该作者
663 用时2分30,应该还能剪枝

使用道具 举报

回复
论坛徽章:
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
147#
发表于 2021-10-7 20:44 来自手机 | 只看该作者
本帖最后由 〇〇 于 2021-10-7 20:55 编辑

772用时2分钟
882转出不来

使用道具 举报

回复
论坛徽章:
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
148#
 楼主| 发表于 2021-10-7 21:27 | 只看该作者
8,8,3 答案是24。把SQL大赛的写法改一下,大胆假设24的摆法存在,再去小心求证,就可以跑出来了。

使用道具 举报

回复
论坛徽章:
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
149#
发表于 2021-10-7 21:38 | 只看该作者

--6*6 + 2
SQL> set timing on
SQL>
SQL> with t(n,c,x,y) as (select level,chr(64+level),ceil(level/6),mod(level-1,6)+1 from dual connect by level<=6*6),
  2       s(lvl,n,
  3       --nlist,
  4       clist) as (select 1,
  5                                 n,
  6                                 --cast(n as varchar2(100)),
  7                                 c
  8                            from t
  9                           where t.n between 1 and 3
10                           union all
11                          select lvl + 1,
12                                 b.n,
13                                 --nlist||','||b.n,
14                                 clist||','||b.c
15                            from s,t b
16                           where s.n < b.n
17                             and (select greatest(sum(case when a.x = b.x then 1 end),
18                                                  sum(case when a.y = b.y then 1 end),
19                                                  sum(case when a.x-b.x = a.y-b.y then 1 end),
20                                                  sum(case when a.x-b.x = b.y-a.y then 1 end)
21                                                  )
22                                    from t a
23                                   where instr(clist||','||b.c,a.c)>0 ) <=2
24                                     and case when lvl+1=2 and b.n between 1 and 6 then 1
25                                              when lvl+1 in (3,4)   and b.n between 7  and 12 then 1
26                                              when lvl+1 in (5,6)   and b.n between 13 and 18 then 1
27                                              when lvl+1 in (7,8)   and b.n between 19 and 24 then 1
28                                              when lvl+1 in (9,10)  and b.n between 25 and 30 then 1
29                                              when lvl+1 in (11,12) and b.n between 31 and 36 then 1
30                                              else 0
31                                         end = 1
32                              )
33  select max(lvl) from s
34  /

  MAX(LVL)
----------
        12

Executed in 1.829 seconds




--7*7 + 2
SQL> set timing on;
SQL>
SQL> with t(n,c,x,y) as (select level,chr(64+level),ceil(level/7),mod(level-1,7)+1 from dual connect by level<=7*7),
  2       s(lvl,n,
  3       --nlist,
  4       clist) as (select 1,
  5                                 n,
  6                                 --cast(n as varchar2(100)),
  7                                 c
  8                            from t
  9                           where t.n between 1 and 4
10                           union all
11                          select lvl + 1,
12                                 b.n,
13                                 --nlist||','||b.n,
14                                 clist||','||b.c
15                            from s,t b
16                           where s.n < b.n
17                             and (select greatest(sum(case when a.x = b.x then 1 end),
18                                                  sum(case when a.y = b.y then 1 end),
19                                                  sum(case when a.x-b.x = a.y-b.y then 1 end),
20                                                  sum(case when a.x-b.x = b.y-a.y then 1 end)
21                                                  )
22                                    from t a
23                                   where instr(clist||','||b.c,a.c)>0 ) <=2
24                                     and case when lvl+1=2          and b.n between 1  and 7  then 1
25                                              when lvl+1 in (3,4)   and b.n between 8  and 14 then 1
26                                              when lvl+1 in (5,6)   and b.n between 15 and 21 then 1
27                                              when lvl+1 in (7,8)   and b.n between 22 and 28 then 1
28                                              when lvl+1 in (9,10)  and b.n between 29 and 35 then 1
29                                              when lvl+1 in (11,12) and b.n between 36 and 42 then 1
30                                              when lvl+1 in (13,14) and b.n between 43 and 49 then 1
31                                              else 0
32                                         end = 1
33                              )
34  select max(lvl) from s
35  /

  MAX(LVL)
----------
        14

Executed in 59.74 seconds

使用道具 举报

回复
论坛徽章:
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
150#
发表于 2021-10-7 22:11 | 只看该作者
--8*8 + 2

SQL>
SQL> with t(n,c,x,y) as (select level,chr(64+level),ceil(level/8),mod(level-1,8)+1 from dual connect by level<=8*8),
  2       s(lvl,n,
  3       --nlist,
  4       clist) as (select 1,
  5                                 n,
  6                                 --cast(n as varchar2(100)),
  7                                 c
  8                            from t
  9                           where t.n between 1 and 4
10                           union all
11                          select lvl + 1,
12                                 b.n,
13                                 --nlist||','||b.n,
14                                 clist||','||b.c
15                            from s,t b
16                           where s.n < b.n
17                             and (select greatest(sum(case when a.x = b.x then 1 end),
18                                                  sum(case when a.y = b.y then 1 end),
19                                                  sum(case when a.x-b.x = a.y-b.y then 1 end),
20                                                  sum(case when a.x-b.x = b.y-a.y then 1 end)
21                                                  )
22                                    from t a
23                                   where instr(clist||','||b.c,a.c)>0 ) <=2
24                                     and case when lvl+1=2          and b.n between 1  and 8  then 1
25                                              when lvl+1 in (3,4)   and b.n between 9  and 16 then 1
26                                              when lvl+1 in (5,6)   and b.n between 17 and 24 then 1
27                                              when lvl+1 in (7,8)   and b.n between 25 and 32 then 1
28                                              when lvl+1 in (9,10)  and b.n between 33 and 40 then 1
29                                              when lvl+1 in (11,12) and b.n between 41 and 48 then 1
30                                              when lvl+1 in (13,14) and b.n between 49 and 56 then 1
31                                              when lvl+1 in (15,16) and b.n between 57 and 64 then 1
32                                              else 0
33                                         end = 1
34                              )
35  select max(lvl) from s
36  /

  MAX(LVL)
----------
        16

Executed in 2172.525 seconds

使用道具 举报

回复

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

本版积分规则 发表回复

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