为方便大家周末休闲的时候玩玩,先放点儿基础的东西。 set nocount on go -- init, 构造空表 declare @t table (n int) insert into @t select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9select row=r.n , col=c.n -- , area = dbo.fn_sudo_area (r.n,c.n) , num = cast(null as int) into tb_sudo from @t r,@t c order by row go /** 根据给出的行、列,返回该点所在单元 */ create function dbo.fn_sudo_area ( @r int, @c int ) returns int as begin return ( ((@r-1)/3) *3+ ((@c-1)/3) )+1 end gocreate procedure proc_showText as select c1=t1.num ,c2=t2.num ,c3=t3.num ,c4=t4.num ,c5=t5.num ,c6=t6.num ,c7=t7.num ,c8=t8.num ,c9=t9.num from (select row,num from tb_sudo where col=1) t1, (select row,num from tb_sudo where col=2) t2, (select row,num from tb_sudo where col=3) t3, (select row,num from tb_sudo where col=4) t4, (select row,num from tb_sudo where col=5) t5, (select row,num from tb_sudo where col=6) t6, (select row,num from tb_sudo where col=7) t7, (select row,num from tb_sudo where col=8) t8, (select row,num from tb_sudo where col=9) t9 where 1=1 and t1.row = t2.row and t1.row = t3.row and t1.row = t4.row and t1.row = t5.row and t1.row = t6.row and t1.row = t7.row and t1.row = t8.row and t1.row = t9.row order by t1.row go-- 登记问题数据 go -- 求解 go -- 输出 exec proc_showText go drop procedure proc_showText drop function dbo.fn_sudo_area drop table tb_sudo go
我打算用十个表 九个小格分别对应九张表 整个大格对应另外一张表 表格式初步定为(id tinyint, content tinyint) X X X --如该小格 对应小表中9行content列数据 表上建check和unique约束 表上建update/insert触发器 X X X X X X在程序前端 取9*9变量或二维数组对应
啥意思?
2. 各位:明天加100分给大家分分;
3. 紫色的那个啥:让他直接跟我说才算数;
4. 关于“数独”(sudoku):9x9个格子里,已有若干数字,其它宫位留白,玩家需要自己按照逻辑推敲出剩下的空格里是什么数字,使得每一行与每一列都有1到9的数字,每个小九宫格里也有1到9的数字,并且一个数字在每个行列及每个小九宫格里都只能出现一次
数独是一个智力小游戏。一个9*9的棋盘,共有9行9列以及9个互不相交的3*3九宫格。里面某些格子开始已经填上了1-9中的一些数字。要求玩家在余下的空格中填上1-9中数字,使得每行,每列和每个3*3九宫格中都正好包含1-9数字各一个。数独游戏保证结果的存在和唯一性。
无限数独下载:http://download.csdn.net/sort/tag/%E6%97%A0%E9%99%90%E6%95%B0%E7%8B%AC/3数独游戏程序:http://blog.csdn.net/mathe/archive/2007/08/23/1755672.aspx
-------------------------------------
你这个题出的也真是缘分 我昨天下班地铁还看到一个女的手机上玩数独 不过我都不确定自己能玩出来哦
我肯定抢答
set nocount on
go
-- init, 构造空表
declare @t table (n int)
insert into @t
select 1 union
select 2 union
select 3 union
select 4 union
select 5 union
select 6 union
select 7 union
select 8 union
select 9select row=r.n , col=c.n
-- , area = dbo.fn_sudo_area (r.n,c.n)
, num = cast(null as int)
into tb_sudo
from @t r,@t c
order by row
go
/** 根据给出的行、列,返回该点所在单元
*/
create function dbo.fn_sudo_area (
@r int, @c int
) returns int
as begin
return ( ((@r-1)/3) *3+ ((@c-1)/3) )+1
end
gocreate procedure proc_showText as
select
c1=t1.num
,c2=t2.num
,c3=t3.num
,c4=t4.num
,c5=t5.num
,c6=t6.num
,c7=t7.num
,c8=t8.num
,c9=t9.num
from
(select row,num from tb_sudo where col=1) t1,
(select row,num from tb_sudo where col=2) t2,
(select row,num from tb_sudo where col=3) t3,
(select row,num from tb_sudo where col=4) t4,
(select row,num from tb_sudo where col=5) t5,
(select row,num from tb_sudo where col=6) t6,
(select row,num from tb_sudo where col=7) t7,
(select row,num from tb_sudo where col=8) t8,
(select row,num from tb_sudo where col=9) t9
where 1=1
and t1.row = t2.row
and t1.row = t3.row
and t1.row = t4.row
and t1.row = t5.row
and t1.row = t6.row
and t1.row = t7.row
and t1.row = t8.row
and t1.row = t9.row
order by t1.row
go-- 登记问题数据
go
-- 求解
go
-- 输出
exec proc_showText
go
drop procedure proc_showText
drop function dbo.fn_sudo_area
drop table tb_sudo
go
在一行/一列/一个(小九宫)区域内,每个数字都要出现一次;
==>某个位置的行/列/区域内未出现过的数字均可能在该位置上;每个数字在一行/一列/一个区域内只能又一次;
==>在某个位置上的数字不可能是在该行/该列/该区域出现过的任何数字;
X X X
X X X在程序前端 取9*9变量或二维数组对应
-------------------------------------------------------------------------------------已有若干数字,其它宫位留白---在哪,怎么分布?