楼主: newkid

[每日一题] PUZZLEUP 2015

[复制链接]
论坛徽章:
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
451#
 楼主| 发表于 2015-12-2 22:49 | 只看该作者
#19 QUEENS                                                                                                  

In how many ways can white and black queens be placed on a 4x4 chess board, such that every row and every column has more white pawns than black pawns?

Note:
-On each square you can place only one pawn (white or black) or you can leave it empty.

If the problem was asked for a 3x3 board, then the answer would be 451.
Examples:

在一个4X4的国际象棋棋盘上,有多少种方法可以放置白色和黑色皇后,使得每一行与每一列的白子数比黑子数更多?
                                                                                                        
注意:                                                                                                  
每个方格你只能放置一个棋子(黑色或白色),你也可以让它空着。
                                                                                                        
如果问的是3×3板的棋盘,那么答案将是451。                                                         

================================
这个比我们的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
452#
发表于 2015-12-3 07:47 | 只看该作者
newkid 发表于 2015-12-2 22:49
#19 QUEENS                                                                                           ...

确实不如比赛难,所以奖品也低一点

使用道具 举报

回复
论坛徽章:
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
453#
发表于 2015-12-3 09:55 | 只看该作者
newkid 发表于 2015-12-2 22:49
#19 QUEENS                                                                                           ...

with t as(select level-1 a from dual connect by level<=4),
a as(select * from(select replace(sys_connect_by_path(a,','),',')p --0白2黑1空
from t
where level=4
connect by prior dbms_random.value is not null
and level<=4)where regexp_count(p,'2')>regexp_count(p,'0')),
b as(select * from(select replace(sys_connect_by_path(p,','),',')b --0白2黑1空
,replace(sys_connect_by_path(substr(p,1,1),','),',')b1
,replace(sys_connect_by_path(substr(p,2,1),','),',')b2
,replace(sys_connect_by_path(substr(p,3,1),','),',')b3
,replace(sys_connect_by_path(substr(p,4,1),','),',')b4
from a
where level=4
connect by prior dbms_random.value is not null
and level<=4)where regexp_count(b1,'2')>regexp_count(b1,'0') and
regexp_count(b2,'2')>regexp_count(b2,'0')and
regexp_count(b3,'2')>regexp_count(b3,'0')and
regexp_count(b4,'2')>regexp_count(b4,'0'))
select count(*) from b;

使用道具 举报

回复
论坛徽章:
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
454#
 楼主| 发表于 2015-12-3 10:11 | 只看该作者
有点慢哦,我笔记本的风扇狂响,被我停了。
我写的版本:
Elapsed: 00:00:00.61

使用道具 举报

回复
论坛徽章:
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
455#
发表于 2015-12-3 10:25 | 只看该作者
newkid 发表于 2015-12-3 10:11
有点慢哦,我笔记本的风扇狂响,被我停了。
我写的版本:
Elapsed: 00:00:00.61

差不多要连接出1亿行

使用道具 举报

回复
论坛徽章:
8
玉兔
日期:2015-11-16 10:18:00铁扇公主
日期:2015-10-27 21:47:42九尾狐狸
日期:2015-12-11 22:31:15
456#
发表于 2015-12-3 10:32 | 只看该作者
这题目也太弱了吧,直接上 M 代码

In[11]:= K = 4;
Length@Select[
  Tuples[Select[Tuples[{-1, 0, 1}, K], Total[#] > 0 &], K],
  Length@Select[Total /@ Transpose[#], # <= 0 &] == 0 &]

Out[12]= 294879

使用道具 举报

回复
论坛徽章:
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
457#
 楼主| 发表于 2015-12-3 10:38 | 只看该作者
lugionline 发表于 2015-12-3 10:32
这题目也太弱了吧,直接上 M 代码

In[11]:= K = 4;

比赛题做出来了没?

使用道具 举报

回复
论坛徽章:
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
458#
发表于 2015-12-3 10:44 | 只看该作者
我第1行写错了,这回对了
with t as(select level-1 a from dual connect by level<=3),
a as(select * from(select replace(sys_connect_by_path(a,','),',')p --0白2黑1空
from t
where level=4
connect by prior dbms_random.value is not null
and level<=4)where regexp_count(p,'2')>regexp_count(p,'0')),
b as(select * from(select replace(sys_connect_by_path(p,','),',')b --0白2黑1空
,replace(sys_connect_by_path(substr(p,1,1),','),',')b1
,replace(sys_connect_by_path(substr(p,2,1),','),',')b2
,replace(sys_connect_by_path(substr(p,3,1),','),',')b3
,replace(sys_connect_by_path(substr(p,4,1),','),',')b4
from a
where level=2
connect by prior dbms_random.value is not null
and level<=2)where regexp_count(b1,'0')<2 and
regexp_count(b2,'0')<2 and
regexp_count(b3,'0')<2 and
regexp_count(b4,'0')<2 ),
b2 as(select * from(
select b.b||c.b b,
b.b1||c.b1 b1,
b.b2||c.b2 b2,
b.b3||c.b3 b3,
b.b4||c.b4 b4 from b,b c)
where regexp_count(b1,'2')>regexp_count(b1,'0') and
regexp_count(b2,'2')>regexp_count(b2,'0')and
regexp_count(b3,'2')>regexp_count(b3,'0')and
regexp_count(b4,'2')>regexp_count(b4,'0'))
select count(*) from b2;

使用道具 举报

回复
论坛徽章:
8
玉兔
日期:2015-11-16 10:18:00铁扇公主
日期:2015-10-27 21:47:42九尾狐狸
日期:2015-12-11 22:31:15
459#
发表于 2015-12-3 10:44 | 只看该作者
newkid 发表于 2015-12-3 10:38
比赛题做出来了没?

比赛题太烦锁了,花了差不多20行M代码

使用道具 举报

回复
论坛徽章:
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
460#
发表于 2015-12-3 10:51 | 只看该作者
lugionline 发表于 2015-12-3 10:44
比赛题太烦锁了,花了差不多20行M代码

这么少,可惜没环境

使用道具 举报

回复

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

本版积分规则 发表回复

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