ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½Ð±Ð³B²z16­Ó¥¿¾ã¼Æªº¤£©w¤èµ{°ÝÃD

½Ð±Ð³B²z16­Ó¥¿¾ã¼Æªº¤£©w¤èµ{°ÝÃD

½Ð±Ð¦U¦ì¤j¤j:
­Y¦³16­ÓÅܶq a,b,c,...,p
¨C­ÓÅܶq³£¬O1¨ì16ªº¥¿¾ã¼Æ¡A¥B¦U¦Û©¼¦¹³£¤£¦P¡A
³o¨ÇÅܶq¨ã¦³¥H¤U³o¨Ç¤èµ{Ãö«Y:
a+b+c+d+e+f+g=49+s
2*b+c+2*d+e+2*f+g=87-s
¨ä¤¤, s=0,1,...,21

h+i+j=d+e+f
k+l+m=b+g+f
n+o+p=b+c+d

§Ú°Ñ¦Òºô¸ô¤@¨Ç¸ê®Æ¡A¥Hs=0,s=1...,s=21¤À¶}³B²z
¥Î°j°éªº¤è¦¡(For Next)¥ý§ä¥X¤Fa¨ìgªº7­ÓÅܶq¡A
¦ý¬O«á¨Ó¥é·Ó¥[¤J¨ä¾l9­ÓÅܶq(h,i,j,...,p)«o¤@ª½·í±¼¡A
¦³ºô¤Í»¡¦]¬°¥Î°j°é¡A³Ì«á·|¬O16^15¡A©Ò¥HµLªk³B²z¡A¦ý¥Ø«e¤]·Q¤£¨ì¨ä¥L¤è¦¡¡A
©Ò¥H·Q½Ð±Ð¦U¦ì¬O¤£¬O¦³¨ä¥L¤è¦¡¥i¥H³B²z©O?
¥H¤U¬O¶]«e7­ÓÅܶqªº»yªk(s=0)

Function Unequal(ParamArray Nums() As Variant) As Integer
Dim intI1 As Integer, intI2 As Integer, l As Integer, u As Integer
l = LBound(Nums())
u = UBound(Nums())
If u - l < 1 Then
Unequal = 3
Exit Function
End If
For intI1 = l To u - 1
For intI2 = intI1 + 1 To u
If Nums(intI1) = Nums(intI2) Then
Unequal = 0
Exit Function
End If
Next
Next
Unequal = 1
End Function

Sub hexagonhive ()
For a = 1 To 16
For b = 1 To 16
For c = 1 To 16
For d = 1 To 16
For e = 1 To 16
For f = 1 To 16
g = 49 - a - b - c - d - e ¡V f
Dim ue As Integer, str As String
ue = Unequal(a, b, c, d, e, f, g)
If ue = 1 And g > 0 And g < 17 And 2 * b + c + 2 * d + e + 2 * f + g = 87 Then
t = t + 1
Cells(t, 1) = a: Cells(t, 2) = b: Cells(t, 3) = c: Cells(t, 4) = d: Cells(t, 5) = e: Cells(t, 6) = f: Cells(t, 7) = g:
End If
Next f, e, d, c, b, a
End Sub

¦^´_ 1# kain
§A§âdim±q°j°é¤¤´£¥X¨Ó¬Ý¬Ý

TOP

§Ú§âÅܼƭ«·s«Å§i¦Ó¤w
¬O¯à¶]¥X¨Óªº (¯Ó®É38¬í)
¶]¥X252ºØ²Õ¦X
  1. Sub hexagonhive()
  2. Dim ue As Integer, str As String
  3. Dim a As Integer, b As Integer, c As Integer, d As Integer, e As Integer, f As Integer, g As Integer
  4. Dim t As Long
  5. t = 0
  6. Debug.Print Time

  7. For a = 1 To 16
  8. For b = 1 To 16
  9. For c = 1 To 16
  10. For d = 1 To 16
  11. For e = 1 To 16
  12. For f = 1 To 16
  13.     g = 49 - a - b - c - d - e - f
  14.     ue = Unequal(a, b, c, d, e, f, g)
  15.    
  16.     If ue = 1 And g > 0 And g < 17 And 2 * b + c + 2 * d + e + 2 * f + g = 87 Then
  17.         t = t + 1
  18.         Cells(t, 1) = a: Cells(t, 2) = b: Cells(t, 3) = c: Cells(t, 4) = d: Cells(t, 5) = e: Cells(t, 6) = f: Cells(t, 7) = g:
  19.     End If
  20. Next f, e, d, c, b, a
  21. Debug.Print Time
  22. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¦³¦h¤Ö¤O¶q´N°µ¦h¤Ö¨Æ¡A¤£­n¤ß¦sµ¥«Ý¡Aµ¥«Ý¤~·|¸¨ªÅ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD