楼主: newkid

[每日一题] puzzleup 2021

[复制链接]
论坛徽章:
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
271#
 楼主| 发表于 2021-10-19 21:30 | 只看该作者
〇〇 发表于 2021-10-19 15:30
还原结果create table chess2 asWITH-------- 先把10个棋子放置在6X6,使得每行每列不超过两个(满足尽量均 ...

这个改得不错!
在做上一题的时候我有想过,当时因为有斜线的要求所以放弃了,这题完全可以用上。

使用道具 举报

回复
论坛徽章:
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
272#
发表于 2021-10-19 23:33 | 只看该作者
〇〇 发表于 2021-10-19 19:55
最后复原的代码难看,你用connect by 写一个?

newkid 的还有你这优化的,还没来得及细看,周末试一试。。

使用道具 举报

回复
论坛徽章:
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
273#
发表于 2021-10-20 08:15 | 只看该作者
本帖最后由 〇〇 于 2021-10-20 08:36 编辑
〇〇 发表于 2021-10-18 09:04
将最后一个改成postgres的语法D:\pgsql140\bin>psql -d testpsql (14.0)输入 "help" 来获取帮助信息.test=# ...

改为mysql8的语法,cast有问题

with RECURSIVE t6(n) as (select 1 union all select n+1 from t6 where n<6)
,
b3(a,b,c,bit)as(select a.n,b.n,c.n,(1<<(a.n-1))+(1<<(b.n-1))+(1<<(c.n-1)) from t6 a,t6 b,t6 c where a.n<b.n and b.n<c.n)
,
b9(b)as(select c.bit*((1<<(r.a-1)*6)+(1<<(r.b-1)*6)+(1<<(r.c-1)*6)) from b3 c,b3 r)
,
t(n,c,x,y)
as(select 1,cast('1' as char(100)),1,1 union all select n+1,cast(n+1 as char(100)),n/6+1,n%6+1 from t where n<6*6)
,
s(lv,n,nlist,blist,px,py)
as(select 1,t.n,t.c,1<<(t.n-1),pow(10,t.x),pow(10,t.y) from t where t.n<=6
union all
select lv+1,b.n,trim(nlist)||','||trim(c),blist+(1<<(b.n-1)),px+pow(10,b.x),py+pow(10,b.y)
from s,t b
where lv<10 and s.n<b.n
and(blist%19<14)
and (instr(px+pow(10,b.x),3)=0 and instr(py+pow(10,b.y),3)=0)
and b.n  between lv/2*6+1 and lv/2*6+6*2
)
select * from s where lv=10 and (lv<3 or not exists(select 1 from b9 where  (blist & b9.b) =0))
limit 10;

+------+------+-------+------------+---------+---------+
| lv   | n    | nlist | blist      | px      | py      |
+------+------+-------+------------+---------+---------+
|   10 |   31 | 1     | 1344948364 | 2122210 | 2122210 |
|   10 |   31 | 1     | 1381024416 | 2222200 | 1222210 |
|   10 |   31 | 1     | 1377970452 | 2212210 | 2212210 |
|   10 |   31 | 1     | 1378485012 | 2221210 | 1222210 |
|   10 |   31 | 1     | 1378403616 | 2222200 | 1222210 |
|   10 |   31 | 1     | 1414047756 | 2222110 | 1222210 |
|   10 |   31 | 1     | 1414055946 | 2222110 | 1222210 |
|   10 |   31 | 1     | 1411982112 | 2222200 | 1222210 |
|   10 |   31 | 1     | 125**8892 | 2221210 | 2122210 |
|   10 |   31 | 1     | 1246364940 | 2221210 | 1222210 |
+------+------+-------+------------+---------+---------+
10 rows in set, 2 warnings (8.55 sec)

mysql> show warnings
    -> ;
+---------+------+-------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                               |
+---------+------+-------------------------------------------------------------------------------------------------------+
| Warning | 1287 | '|| as a synonym for OR' is deprecated and will be removed in a future release. Please use OR instead |
| Warning | 1287 | '|| as a synonym for OR' is deprecated and will be removed in a future release. Please use OR instead |
+---------+------+-------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)把||操作符改为concat()函数可以了
with RECURSIVE t6(n) as (select 1 union all select n+1 from t6 where n<6)
,
b3(a,b,c,bit)as(select a.n,b.n,c.n,(1<<(a.n-1))+(1<<(b.n-1))+(1<<(c.n-1)) from t6 a,t6 b,t6 c where a.n<b.n and b.n<c.n)
,
b9(b)as(select c.bit*((1<<(r.a-1)*6)+(1<<(r.b-1)*6)+(1<<(r.c-1)*6)) from b3 c,b3 r)
,
t(n,c,x,y)
as(select 1,cast('1' as char(100)),1,1 union all select n+1,cast(n+1 as char(100)),n/6+1,n%6+1 from t where n<6*6)
,
s(lv,n,nlist,blist,px,py)
as(select 1,t.n,t.c,1<<(t.n-1),pow(10,t.x),pow(10,t.y) from t where t.n<=6
union all
select lv+1,b.n,concat(trim(nlist),',',trim(c)),blist+(1<<(b.n-1)),px+pow(10,b.x),py+pow(10,b.y)
from s,t b
where lv<10 and s.n<b.n
and(blist%19<14)
and (instr(px+pow(10,b.x),3)=0 and instr(py+pow(10,b.y),3)=0)
and b.n  between lv/2*6+1 and lv/2*6+6*2
)
select * from s where lv=10 and (lv<3 or not exists(select 1 from b9 where  (blist & b9.b) =0))
limit 10;

+------+------+-----------------------------+------------+---------+---------+
| lv   | n    | nlist                       | blist      | px      | py      |
+------+------+-----------------------------+------------+---------+---------+
|   10 |   31 | 6,8,10,15,16,21,23,26,29,31 | 1381024416 | 2222200 | 1222210 |
|   10 |   31 | 3,5,9,12,14,18,22,26,29,31  | 1377970452 | 2212210 | 2212210 |
|   10 |   31 | 3,5,9,10,18,20,22,26,29,31  | 1378485012 | 2221210 | 1222210 |
|   10 |   31 | 6,9,11,15,16,20,22,26,29,31 | 1378403616 | 2222200 | 1222210 |
|   10 |   31 | 3,4,12,14,16,20,23,27,29,31 | 1414047756 | 2222110 | 1222210 |
|   10 |   31 | 2,4,12,15,16,20,23,27,29,31 | 1414055946 | 2222110 | 1222210 |
|   10 |   31 | 3,4,8,12,17,21,24,26,28,31  | 125**8892 | 2221210 | 2122210 |
|   10 |   31 | 3,4,9,11,18,20,23,26,28,31  | 1246364940 | 2221210 | 1222210 |
|   10 |   31 | 6,8,11,15,16,21,23,26,28,31 | 1246807200 | 2222200 | 1222210 |
|   10 |   31 | 2,4,11,14,18,21,24,27,28,31 | 1284645898 | 2222110 | 2122210 |
+------+------+-----------------------------+------------+---------+---------+
10 rows in set (7.55 sec)

cast as char实际上达到了varchar的效果
mysql> select concat(cast(1 as char),cast(32 as char));
+------------------------------------------+
| concat(cast(1 as char),cast(32 as char)) |
+------------------------------------------+
| 132                                      |
+------------------------------------------+
1 row in set (0.00 sec)

mysql> select concat(cast(1 as char(10)),cast(32 as char));
+----------------------------------------------+
| concat(cast(1 as char(10)),cast(32 as char)) |
+----------------------------------------------+
| 132                                          |
+----------------------------------------------+

除法也需要改为floor,和oracle差不多,也能检测出第一个t6写成t的错误,速度和postgresql差不多

mysql> with RECURSIVE t6(n) as (select 1 union all select n+1 from t6 where n<6)
    -> ,
    -> b3(a,b,c,bit)as(select a.n,b.n,c.n,(1<<(a.n-1))+(1<<(b.n-1))+(1<<(c.n-1)) from t6 a,t6 b,t6 c where a.n<b.n and b.n<c.n)
    -> ,
    -> b9(b)as(select c.bit*((1<<(r.a-1)*6)+(1<<(r.b-1)*6)+(1<<(r.c-1)*6)) from b3 c,b3 r)
    -> ,
    -> t(n,c,x,y)
    -> as(select 1,cast('1' as char(100)),1,1 union all select n+1,cast(n+1 as char(100)),floor(n/6)+1,n%6+1 from t where n<6*6)
    -> ,
    -> s(lv,n,nlist,blist,px,py)
    -> as(select 1,t.n,t.c,1<<(t.n-1),pow(10,t.x),pow(10,t.y) from t where t.n<=6
    -> union all
    -> select lv+1,b.n,concat(nlist,',',c),blist+(1<<(b.n-1)),px+pow(10,b.x),py+pow(10,b.y)
    -> from s,t b
    -> where lv<10 and s.n<b.n
    -> and (instr(px+pow(10,b.x),3)=0 and instr(py+pow(10,b.y),3)=0)
    -> and b.n  between floor(lv/2)*6+1 and floor(lv/2)*6+6*2
    -> )
    -> select count(*) from s where lv=10 and not exists(select 1 from b9 where  (blist & b9.b) =0)
    -> ;
+----------+
| count(*) |
+----------+
|    32400 |
+----------+
1 row in set (2 min 59.69 sec)

使用道具 举报

回复
论坛徽章:
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
274#
发表于 2021-10-20 21:29 来自手机 | 只看该作者
No: 08       October 20, 2021

POINTS AND COLOR LINES

POINTS AND COLOR LINES

There are X points on a plain paper such that no three of them are collinear. Using four different colors, you will draw lines connecting each point with every other point. The condition is that none of the triangles formed by these connections (and having these points as corners) would be monochromic.

What is the maximum possible value for X?


点和色线

在一张普通纸上有 X 个点,它们中没有三个共线。 使用四种不同的颜色,您将绘制连接每个点与其他点的线。 条件是由这些连接(并以这些点为角)形成的三角形都不是单色的。

X 的最大可能值是多少?

使用道具 举报

回复
论坛徽章:
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
275#
发表于 2021-10-20 21:32 来自手机 | 只看该作者
感觉穷举就可以

使用道具 举报

回复
论坛徽章:
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
276#
 楼主| 发表于 2021-10-20 21:33 | 只看该作者

使用道具 举报

回复
论坛徽章:
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
277#
发表于 2021-10-20 22:13 | 只看该作者
〇〇 发表于 2021-10-19 10:09
找到原因了,计算位图的power括号写错了--oracle sqlcreate table chess6f aswith t6(n) as (select 1 from ...

with t6(n) as (select 1 from dual union all select n+1 from t6 where n<6)
,
b3(a,b,c,bit)as(select a.n,b.n,c.n,(power(2,a.n-1))+(power(2,b.n-1))+(power(2,c.n-1)) from t6 a,t6 b,t6 c where a.n<b.n and b.n<c.n)
,
b9(b)as(select c.bit*(power(2,(r.a-1)*6)+power(2,(r.b-1)*6)+power(2,(r.c-1)*6)) from b3 c,b3 r)

这里 b3 好理解,b9 我知道你算的400个组合的掩码,但这为什么是掩码 c.bit*(power(2,(r.a-1)*6)+power(2,(r.b-1)*6)+power(2,(r.c-1)*6))   能细将一下吗?

使用道具 举报

回复
论坛徽章:
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
278#
 楼主| 发表于 2021-10-21 05:05 | 只看该作者
第八题似乎还没有定论,网上可以查到论文,只是证明出现单色三角形的上限不超过62。

使用道具 举报

回复
论坛徽章:
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
279#
发表于 2021-10-21 06:07 来自手机 | 只看该作者
b9是b3在3行出现,如果出现在第一行,保持不变,第二行就乘以2的六次方,以此类推

使用道具 举报

回复
论坛徽章:
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
280#
发表于 2021-10-21 08:46 | 只看该作者
newkid 发表于 2021-10-21 05:05
第八题似乎还没有定论,网上可以查到论文,只是证明出现单色三角形的上限不超过62。

假定这些点都在圆周上,从一个顶点连到其它顶点有n-1个弦,总共有n(n-1)/2个弦,
从一点引出两条弦,总共有c(n-1,2)个∠,加上第三边,可组成c(n-1,2)个三角形

使用道具 举报

回复

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

本版积分规则 发表回复

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