楼主: 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
91#
发表于 2021-10-3 13:21 | 只看该作者
〇〇 发表于 2021-10-3 11:16
你的2,3形有几个  substr(v,4,3)=000 or substr2,1||5,1||8,1=000

240 和 240

使用道具 举报

回复
论坛徽章:
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
92#
发表于 2021-10-3 13:35 来自手机 | 只看该作者
谢谢你

使用道具 举报

回复
论坛徽章:
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
93#
 楼主| 发表于 2021-10-3 22:21 | 只看该作者
我的写法也是2826:

with
c as (select 0 c from dual union all select 1 from dual union all select 2 from dual union all select 4 from dual)
,t (lvl,colors,painted,str) as (
select 1,c,decode(c,0,0,1),cast(c as varchar2(10)) from c
union all
select t.lvl+1,t.colors+c.c-bitand(t.colors,c.c),t.painted + decode(c.c,0,0,1),t.str||c
  from t,c
where t.lvl<9
       and t.painted + decode(c.c,0,0,1)<=5
       and (c.c>0 and (t.lvl not in (3,6) and substr(t.str,t.lvl,1)<>c  --------- 相邻不能同色
                       or t.lvl in (3,6)
                      )
                  and (t.lvl not in (1,2) and substr(t.str,t.lvl-2,1)<>c
                       or t.lvl in (1,2)
                      )
                  and (t.lvl<8   ------- 最后一块如果上色,不能孤立
                       or t.lvl=8 and (substr(t.str,6,1)>'0' or substr(t.str,8,1)>'0')
                      )
             or
             -- 排除以前出现的孤立色块
             c.c=0 and (t.lvl<3
                        or t.lvl=3 and not (substr(t.str,1,1)>0 and substr(t.str,2,1)=0)
                        or t.lvl=4 and not (substr(t.str,1,1)=0 and substr(t.str,2,1)>0 and substr(t.str,3,1)=0)
                        or t.lvl=5 and not (substr(t.str,2,1)=0 and substr(t.str,3,1)>0)
                        or t.lvl=6 and not (substr(t.str,1,1)=0 and substr(t.str,4,1)>0 and substr(t.str,5,1)=0)
                        or t.lvl=7 and not (substr(t.str,2,1)=0 and substr(t.str,4,1)=0 and substr(t.str,5,1)>0 and substr(t.str,6,1)>0)
                                   and not (substr(t.str,4,1)=0 and substr(t.str,7,1)>0)
                        or t.lvl=8 and not (substr(t.str,3,1)=0 and substr(t.str,5,1)=0 and substr(t.str,6,1)>0)
                                   and not (substr(t.str,5,1)=0 and substr(t.str,7,1)=0 and substr(t.str,8,1)>0)
                        )
           )
)
select count(*) from t where colors=7 and painted=5 and lvl=9;

给加菲猫转个章。

使用道具 举报

回复
论坛徽章:
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#
发表于 2021-10-3 23:12 来自手机 | 只看该作者
先存后看

使用道具 举报

回复
论坛徽章:
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
95#
 楼主| 发表于 2021-10-3 23:44 | 只看该作者

递归顺序:按照下图从左到右,从上到下
123
456
789
逐个把格子拼上去。每拼上一个格子有四种可能值。
在递归过程中要今早发现不合格的图案进行剪枝,有几种剪枝条件:
1. 上色的格子总数不能超过5
2. 如果拼上去的色块是有颜色的,要检查正上方和左方格子,不能同色。
3. 图中不能出现孤立的色块。所谓孤立色块是指上下左右都为空白的色块,看起来像个十字架。一旦出现这种情形则无需继续。
   由于递归顺序的实现,整个十字架最后判断的是下方的方格,然后是右边的方格。这两个确定了十字架中心是否为孤立色块。上下左右的邻居在边界位置可能不完整,所以边界的孤立色块判断逻辑有所不同。因为形状只有3X3, 我用枚举实现了,要通用的话,必须用BITAND把十字架抠出来判断。
   目前我写的代码中孤立色块是这样判断的:
   如果拼上去的这一块为空白,那么正上方有可能出现孤立色块;
   如果当前行已经是最后一行,左方也有可能出现孤立色块;
   如果当前是最后一块(第九块),而且有颜色,则要判断上边和左边的邻居是否为空白。
   除了上述情形,其他的孤立色块都不用考虑,因为如果有出现的话也被前几次递归给排除掉了。

使用道具 举报

回复
论坛徽章:
0
96#
发表于 2021-10-4 01:09 来自手机 | 只看该作者
Missed U and J shapes besides T and +.  So each cell may not be equal here.  Now it is like sudoku grid (no formula fo total valid count) with constraint depending on each peer setting (eg neighbor cells).  I have to give up iPhone which has little room on typing error or you

使用道具 举报

回复
论坛徽章:
0
97#
发表于 2021-10-4 01:20 来自手机 | 只看该作者
Missed L shape too.

使用道具 举报

回复
论坛徽章:
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
98#
发表于 2021-10-4 08:49 | 只看该作者
newkid 发表于 2021-10-3 23:44
递归顺序:按照下图从左到右,从上到下123456789逐个把格子拼上去。每拼上一个格子有四种可能值。在递归过 ...

谢谢你的章。
我孤立色块的判断,判断条件如果放到 递归WITH里面,但感觉向左和向下的块是后面的迭代才会出现的,所以不好搞,原来可以相你这样逐个判断,用OR 条件!

使用道具 举报

回复
论坛徽章:
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#
发表于 2021-10-4 13:16 来自手机 | 只看该作者
t.lvl=7 and not (substr(t.str,2,1)=0 and substr(t.str,4,1)=0 and substr(t.str,5,1)>0 and substr(t.str,6,1)>0) 中的  and substr(t.str,6,1)>0条件多余?  

使用道具 举报

回复
论坛徽章:
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
100#
发表于 2021-10-4 13:25 来自手机 | 只看该作者
t.lvl大于4时,已着色格子不足t.lvl-4的也可排除

使用道具 举报

回复

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

本版积分规则 发表回复

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