双色球红球6个组合要按照下列要求输出

yanchenfeng 2018-02-19 02:24:58
据说,红球6 一共有110万个组合, 哪位大神有所有的EXCEL格式组合文件,可以发邮箱:305975467;或者给一个百度网盘的分享下载链接,跪谢!
篮球不要,输出的六个红球要满足一下条件怎么删选,其中两个球是连号的,有一个球是其中两个球的和,例如:03、11、12、16、21、23,其中11/12连号,23=11+12,像这样怎么删选号码
...全文
1028 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zbdzjx 2018-02-23
  • 打赏
  • 举报
回复
引用 10 楼 yanchenfeng 的回复:
别的联系方式有吗,邮箱,我想交流一下,其中六个数字中的任意两个数字之和等于另个数字,还有六个数字中会出现连号,连号和两个数字之和没有联系,但是要同时存在,你是用什么语言写,就数据库,要怎么学习
修改后的SQL语句如下,共493848条记录。
with t1 as
(
select number+1 c from master..spt_values where type='P' and number<33
)
, t2 as
(
select a.c c1, b.c c2, c.c c3, d.c c4, e.c c5, f.c c6 
from t1 a
inner join t1 b on a.c<b.c
inner join t1 c on b.c<c.c
inner join t1 d on c.c<d.c
inner join t1 e on d.c<e.c
inner join t1 f on e.c<f.c
)
select * from t2
where
(c1+1=c2 or c2+1=c3 or c3+1=c4 or c4+1=c5 or c5+1=c6)
and
(
     c1+c2=c3 or c1+c2=c4 or c1+c2=c5 or c1+c2=c6
  or c1+c3=c4 or c1+c3=c5 or c1+c3=c6
  or c1+c4=c5 or c1+c4=c6
  or c1+c5=c6
  
  or c2+c3=c4 or c2+c3=c5 or c2+c3=c6
  or c2+c4=c5 or c2+c4=c6
  or c2+c5=c6
  
  or c3+c4=c5 or c3+c4=c6
  or c3+c5=c6
  
  or c4+c5=c6
)
  • 打赏
  • 举报
回复
那个是用到额外的一个自定义函数 来判断 但是觉得和你原先的 题意不符 就没留了~~ 你可以加我QQ 闲了重写下给你 343774501
  • 打赏
  • 举报
回复
再修改下,S少套个sign 函数,现在结果是31488条
declare @maxN tinyint =33,@L tinyint =6
declare  @t0 table(n tinyint primary key,n2 varchar(2))
insert @t0 select number n,n2=right('0'+cast(number as varchar(2)),2) from master..spt_values where type='p' and number between 1 and @maxN
;with 
t0 as
	(select * from @t0)
,t1 as
	(select 1 L,n,P=cast(n2+',' as varchar(18)),S=0 
	from t0 
	where n<=@maxN/2 and n<=@maxN-(@L*2-3)
	union all
	select L=L+1,t0.n,P=cast(P+n2+',' as varchar(18)),S=(case when S>0 then S when t1.n=t0.n-1 then L else 0 end)
	from t1 
		inner join t0 on t0.n >t1.n+sign(S) and t0.n<=case when L=@L-1 and S=0 then t1.n+1 when L=@L-1 then @maxN else @maxN-(@L-L)*2+3-sign(S) end and L<@L
	)
select a.P,S from t1 a where L=@L and S<=@L-2 
	and charindex(right('0'+cast(cast(substring(P,S*3-2,2)as tinyint)+cast(substring(P,S*3+1,2)as tinyint)as varchar(2)),2),substring(P,S*3+4,12))>0
order by P,S
  • 打赏
  • 举报
回复
写错了一个地方,现在5秒出结果了,一共24398条
declare @maxN int =33,@L int =6
declare  @t0 table(n int primary key,n2 varchar(2))
insert @t0 select number n,n2=right('0'+cast(number as varchar(2)),2) from master..spt_values where type='p' and number between 1 and @maxN
;with 
t0 as
	(select * from @t0)
,t1 as
	(select 1 L,n,P=cast(n2+',' as varchar(18)),S=0 
	from t0 
	where n<=@maxN/2 and n<=@maxN-(@L*2-3)
	union all
	select L=L+1,t0.n,P=cast(P+n2+',' as varchar(18)),S=(case when S>0 then S when t1.n=t0.n-1 then L else 0 end)
	from t1 
		inner join t0 on t0.n >t1.n+S and t0.n<=case when L=@L-1 and S=0 then t1.n+1 when L=@L-1 then @maxN else @maxN-(@L-L)*2+3-sign(S) end and L<@L
	)
select a.P,S from t1 a where L=@L and S<=@L-2 
	and charindex(right('0'+cast(cast(substring(P,S*3-2,2)as tinyint)+cast(substring(P,S*3+1,2)as tinyint)as varchar(2)),2),substring(P,S*3+4,12))>0
order by P,S
  • 打赏
  • 举报
回复
代码我上面有贴 按我理解的题意是 只有2个数字为连号 且这2个数字之和 等于 6数之一(最后那个sql 按此题意解答) 我觉得这类型题 用sql 并不是最好 客户端应用跑最快应该
yanchenfeng 2018-02-22
  • 打赏
  • 举报
回复
上面那个346579这个代码有吗?跑出来的结果文档有吗?客户端应用是哪个,是不是数据库客户端
  • 打赏
  • 举报
回复
我开始理解错题意 重新计算了下 当有且只有一个连号 并且连号2个数等于 其中6数之一 ,一共是45451条记录
zbdzjx 2018-02-22
  • 打赏
  • 举报
回复
有连号,且连号相加等于另一个号——这个条件的,有63683条记录。
yanchenfeng 2018-02-22
  • 打赏
  • 举报
回复
别的联系方式有吗,邮箱,我想交流一下,其中六个数字中的任意两个数字之和等于另个数字,还有六个数字中会出现连号,连号和两个数字之和没有联系,但是要同时存在,你是用什么语言写,就数据库,要怎么学习
yanchenfeng 2018-02-22
  • 打赏
  • 举报
回复
这么厉害你好,你用数据库写的。之前说的34万条 是全部,还是后面的3万多条,代码能不能给我交流一下
  • 打赏
  • 举报
回复
测试了下 满足条件是 346579 条
  • 打赏
  • 举报
回复

为了计算 任意2个元素和 等于另一个 多跑2分半左右
qq_26209813 2018-02-21
  • 打赏
  • 举报
回复
楼主好高深............................
  • 打赏
  • 举报
回复
前面都简单 最后个两球之和 可能稍微复杂点

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧