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