网易有道难题,铩羽而归。

5月31日参加 网易有道难题 ,结果铩羽而归。

先做的是500分题目:
题目要求:双倍超立方数是指一个正整数可以正好被拆分为两种不同的a^3+b^3的方式,其中a,b均为整数且0<a<=b。对于任何一个指定的 int n, 返回所有的小于等于n的双倍超立方数的个数。
我的解法(vb),不知道正确不正确:

Public Function count(n As Long) As Long

Dim d As Long

d = n ^ (1 / 3) + 1

Dim i As Long
Dim j As Long
Dim k As Long

Dim arrayA() As Long
Dim arrayB() As Long
Dim uA As Long

ReDim arrayA(0)
ReDim arrayB(0)

arrayA(0) = 0
arrayB(0) = 0

Dim count1 As Long
count = 0

Dim uboundA1 As Long
Dim uboundA2 As Long

For i = 1 To n

    For j = 1 To d
      
        For k = j To d
           
            If k > j Then
                If i = j ^ 3 + k ^ 3 Then
                    'Debug.Print "i=" & i
                        uboundA1 = UBound(arrayA)
                        For uA = 0 To uboundA1
                            If i = arrayA(uA) Then
                                arrayB(uA) = arrayB(uA) + 1
                            Else
                                ReDim Preserve arrayA(uboundA1 + 1)
                                    arrayA(uboundA1 + 1) = i
                                ReDim Preserve arrayB(uboundA1 + 1)
                                    arrayB(uboundA1 + 1) = 1
                            End If
                        Next

                End If
            End If
        Next
       
       
    Next

Next
For uA = 0 To UBound(arrayB)
    If arrayB(uA) = 2 Then
        count1 = count1 + 1
    End If
Next

count = count1

End Function


经验与教训:比赛的时候千万要关手机,就是接了两个电话,结果我刚好在编译器里面编辑好答案,刚拷贝到考场程序里面时间就到了,如果不接那两个电话应该可以提交答案。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值