ความคิดเห็นที่ 10
ผมลองใช้ brute force กับข้อ 5 แล้วก็ยังไม่ออกครับ แปลกจัง คิดว่าลองทุกกรณีแล้วนา -__-"
อันนี้เป็นโค้ดของ Visual Basics ใน EXCEL ครับ
Dim N(1 To 9, 1 To 9) As Variant Dim Check(1 To 9, 1 To 9) As Variant Dim Memb(1 To 9, 1 To 9) As Variant Dim QQ(1 To 7) As Integer Dim Row1(1 To 7) As Integer Dim Col1(1 To 7) As Integer Dim Value1(1 To 7, 1 To 7) As Integer Sub SearchMethod() CheckTime1 = Timer CheckN = 0 For i5 = 1 To 81 For j5 = 10 To 20 Cells(20 + i5, j5) = "" Next j5 Next i5 For i = 1 To 9 For j = 1 To 9 If Cells(i, j) = "" Then CheckN = CheckN + 1 Memb(i, j) = "" Else Memb(i, j) = 1 End If Next j Next i If CheckN = 0 Then Exit Sub For i = 1 To 9 For j = 1 To 9 Cells(i + 10, j) = "" Next j Next i CountSp = 0 Do StopSearch = False ContinueSolving = 0 For i = 1 To 9 For j = 1 To 9 N(i, j) = Cells(i, j) If N(i, j) <> "" Then ContinueSolving = ContinueSolving + 1 End If Next j Next i CountSp = CountSp + 1 For i = 1 To 9 For j = 1 To 9 If N(i, j) = "" Then If i <= 3 And j <= 3 Then 'BN(i, j) = 1 Si = 1 Ei = 3 Sj = 1 Ej = 3 ElseIf i <= 3 And j <= 6 And j > 3 Then 'BN(i, j) = 2 Si = 1 Ei = 3 Sj = 4 Ej = 6 ElseIf i <= 3 And j <= 9 And j > 6 Then 'BN(i, j) = 3 Si = 1 Ei = 3 Sj = 7 Ej = 9 ElseIf i <= 6 And i > 3 And j <= 3 Then 'BN(i, j) = 4 Si = 4 Ei = 6 Sj = 1 Ej = 3 ElseIf i <= 6 And i > 3 And j <= 6 And j > 3 Then 'BN(i, j) = 5 Si = 4 Ei = 6 Sj = 4 Ej = 6 ElseIf i <= 6 And i > 3 And j <= 9 And j > 6 Then 'BN(i, j) = 6 Si = 4 Ei = 6 Sj = 7 Ej = 9 ElseIf i <= 9 And i > 6 And j <= 3 Then 'BN(i, j) = 7 Si = 7 Ei = 9 Sj = 1 Ej = 3 ElseIf i <= 9 And i > 6 And j <= 6 And j > 3 Then 'BN(i, j) = 8 Si = 7 Ei = 9 Sj = 4 Ej = 6 ElseIf i <= 9 And i > 6 And j <= 9 And j > 6 Then 'BN(i, j) = 9 Si = 7 Ei = 9 Sj = 7 Ej = 9 End If nn = 0 For k = 1 To 9 Search1 = True For jj = 1 To 9 If k = N(i, jj) Then Search1 = False End If If k = N(jj, j) Then Search1 = False End If Next jj For ll = Si To Ei For mm = Sj To Ej If k = N(ll, mm) Then Search1 = False End If Next mm Next ll If Search1 = True Then nn = nn + 1 Cells(20 + j + 9 * (i - 1), 10) = "(" & i & ", " & j & ")" Cells(20 + j + 9 * (i - 1), 10 + nn) = k 'For iii = 1 To 9 ' For jjj = 1 To 9 ' N(iii, jjj) = Cells(iii, jjj) ' Next jjj 'Next iii End If If k = 9 Then Cells(20 + j + 9 * (i - 1), 20) = nn For iiii = 1 To 81 If Cells(20 + iiii, 20) = 1 Then LocationC = Cells(20 + iiii, 10) ValueC = Cells(20 + iiii, 11) LocI = CInt(Mid(LocationC, InStr(1, LocationC, "(") + 1, 1)) LocJ = CInt(Mid(LocationC, InStr(1, LocationC, ")") - 1, 1)) Cells(LocI, LocJ) = ValueC N(LocI, LocJ) = ValueC End If Next iiii StopSearch = True For iiii = 1 To 9 For jjjj = 1 To 9 If N(iiii, jjjj) = "" Then StopSearch = False Next jjjj Next iiii Next k End If Next j Next i If CountSp = 10 Then Sheets("Sheet1").Select kkkkk = "" Countk = 0 For i = 21 To 101 kkkkk = Cells(i, 20) If kkkkk = 0 Then Countk = Countk + 1 Sheets("sheet2").Select Nnum = Cells(65535, 13) Cells(9 + Nnum, 14) = "Tested & Not passed" Sheets("Sheet1").Select End If Next i If Countk = 0 Then MsgBox "Found it" End If Exit Sub End If For i5 = 1 To 81 For j5 = 10 To 20 Cells(20 + i5, j5) = "" Next j5 Next i5 If ContinueSolving = 0 Then StopSearch = True Loop Until StopSearch = True Or CountSp > 30 For i = 1 To 9 For j = 1 To 9 Cells(i + 10, j) = Memb(i, j) Next j Next i CheckTime2 = Timer MsgBox "Time spent = " & Format(CheckTime2 - CheckTime1, "0.00") & " seconds" End Sub
จากคุณ :
Practical x 2
- [
3 ต.ค. 48 22:31:32
]
|
|
|