ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: northwolves

[Excel 程序开发] [开_102]一道趣味算术题

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-7-10 01:27 | 显示全部楼层
QUOTE:
以下是引用lotustower在2006-7-10 1:20:55的发言:

Almost-Langford numbers , written by pgc01.

Option Explicit
Option Base 1
Const lCol As Long = 1 ' Writes in Column A

Sub AlmostLangford()
Dim iDigits(), iNDigits As Integer, lRow As Long
   
    For iNDigits = 2 To 18 Step 2
        ReDim iDigits(iNDigits)
        Call AlmostLangfordN(iDigits, lRow)
    Next

End Sub

Sub AlmostLangfordN(ByRef iDigits(), ByRef lRow As Long)
Dim iPosFree As Integer, iDigitsTmp(), iDigit As Integer
Dim iNDigits As Integer, i As Integer

    iNDigits = UBound(iDigits)
    Do While True
        'Checks if last free position was filled
        If iPosFree <> 0 Then If IsEmpty(iDigits(iPosFree)) Then Exit Sub
        'Determines next free position
        For iPosFree = iPosFree + 1 To iNDigits
            If IsEmpty(iDigits(iPosFree)) Then Exit For
        Next
        If iPosFree = iNDigits + 1 Then Exit Sub

        ' Tries all digits
        For iDigit = 0 To 9
            If iPosFree + iDigit + 1 > iNDigits Then Exit For
            ' Checks if digit already used
            For i = 1 To iNDigits
                If iDigits(i) = iDigit And Not IsEmpty(iDigits(i)) Then Exit For
            Next
            ' Cannot start with zero
            If i > iNDigits And Not (iPosFree = 1 And iDigit = 0) Then
                If IsEmpty(iDigits(iPosFree + iDigit + 1)) Then
                    ' Initialises idigitstmp
                    ReDim iDigitsTmp(iNDigits)
                    For i = 1 To iNDigits
                        iDigitsTmp(i) = iDigits(i)
                    Next
                    iDigitsTmp(iPosFree) = iDigit
                    iDigitsTmp(iPosFree + iDigit + 1) = iDigit
                   
                    ' Checks if array is full (Almost-Langford number)
                    For i = 1 To iNDigits
                        If IsEmpty(iDigitsTmp(i)) Then Exit For
                    Next
                    If i > iNDigits Then
                        lRow = lRow + 1
                        Cells(lRow, lCol) = "'" & Join(iDigitsTmp, "")
                    Else
                        Call AlmostLangfordN(iDigitsTmp, lRow) 'iDigit + 1
                    End If
                End If
            End If
        Next iDigit
    Loop

End Sub

Congratulations!!! Very fast!!!! But 0 should be removed.

TA的精华主题

TA的得分主题

发表于 2006-7-10 15:20 | 显示全部楼层

3个N,不知是不是这样,不过我做出来1-9中只有n=9有解

 

tKPYgwYY.rar (106.57 KB, 下载次数: 67)

TA的精华主题

TA的得分主题

发表于 2006-7-16 14:17 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-7-17 15:26 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

厉害呀,说实话,还没有看太明白

TA的精华主题

TA的得分主题

发表于 2006-8-5 16:41 | 显示全部楼层

证明4k+1或4k+2无解就比较容易,由于偶数的间距为偶数,奇数间距为奇数,{1,1,2,2,3,3。。。。n,n}间距总值为零,任意调换两数,则间距变化为偶数,而1到n求和值为偶数才符合条件,亦即1到n之间奇数个数为偶数。4k+1或4k+2明显不符合条件.

TA的精华主题

TA的得分主题

发表于 2006-11-30 18:37 | 显示全部楼层
看着就晕了,各位高手!!!

TA的精华主题

TA的得分主题

发表于 2009-4-25 15:54 | 显示全部楼层
原帖由 northwolves 于 2006-7-10 00:59 发表
n=3&nbsp;&nbsp;&nbsp; 2n=4&nbsp;&nbsp;&nbsp; 2n=7&nbsp;&nbsp;&nbsp; 52n=8&nbsp;&nbsp;&nbsp; 300n=11&nbsp;&nbsp; 35584n=12&nbsp;&nbsp; 216288n=15&nbsp;&nbsp; 79619280n=16&nbsp;&nbsp; 653443600n=19&nbsp ...

n=23 7598911885030976

TA的精华主题

TA的得分主题

发表于 2009-7-4 11:21 | 显示全部楼层
代码太多,,数学题解得太好了。

TA的精华主题

TA的得分主题

发表于 2012-10-22 15:54 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
太晕了,都没看明白是怎么回事啊。{:soso_e125:}

TA的精华主题

TA的得分主题

发表于 2013-1-28 21:44 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
高人。。。。

点评

请发些实质性的东西,不要重复的几句话.  发表于 2013-1-30 11:54
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-5 10:02 , Processed in 0.046484 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表