topic:
The famous mathematician Gauss, the nineteenth century, presented that eight queen on 8 × 8 chess chess boards made it could not attack each other, let alone two queen, you can't be in the same line, the same column or the same oblique line. , Ask how many swings.
analysis:
In fact, the problem can be converted to 12345678 to satisfy a certain condition (the line is not equal, the column is not equal, just set it is not in the same oblique line, the slope is not 1 or -1).
Write the following in a shorter time by using non-recursive mode in the previous two days (.http: //blog.9cbs.net/northwolves/archive/2004/07/21/47601.aspx) Code, the test speed is also:
Code:
'Add a TextBox (with multiline = true and scrollbars = 2 vertical, and a commandbutton
Private Sub Queens 8 (Byref Result () AS String) 'The process of calculating the eight queen issues DIM I as long, J AS integer, k as integer' cycle variable DIM FIT AS BOOLEAN 'determines whether it meets the requirements DIM ALL (1 to 8), OUT (1 to 8) AS String 'Used to Output DIM TEMP1 AS Long, Temp2 AS Integer' Supplied Conversion Intermediate Variable for i = 1 To 40320 'Extuncture 8! ALL (1) = 1Temp1 = Ifor J = 2 TO 8TEMP2 = TEMP1 MOD J 'Hybrids TEMP1 = TEMP1 / JIF TEMP2 = 0 THENALL (J) = J' Temp2 is 0 placed in the last Elsefor K = J to Temp2 1 Step -1all (k) = all (k - 1) 'Temp2 Elements After a NEXTALL (TEMP2) = J' TEMP2 is not 0, the end ifnext 'before the TEMP2 element is 11345678 to get one arrangement of 12345678
Fit = true 'initialization variable
'Cycle to determine whether there are two queen to eat for J = 1 to 8for k = 8 to 1 step -1if not k = j tell ABS ((all (k) - all (j)) = ABS (J - K ) Thenfit = falsegoto pass' jumps out of the loop END IFEND IFNEXTNEXT
If Fit Then 'meets the condition when Num = Num 1' Output number redim preserve result (1 to num) for j = 1 to 8Out (j) = string (8, strconv ("□", vbwide))))) MID (OUT J), All (j), 1) = STRCONV ("Q", VBWIDE) NextResult (NUM) = "& Num &" Method: "& Vbcrlf & Join (Out, VBCRLF) 'Output NUM 8 Queen's post-placed state End ifpass: Nextend Sub
Private sub fascist1_click () Dim Result () AS StringText1.text = "" Queens8 ResultText1.text = Join (Result, VBCRLF & VBCRLF) End Sub
Output:
First method: □□□□ □ □□□□□□□□□ q □□ □□□□□□□□□□□ □□□□ q □□□□ q □□□□□ □ □ □ □ □ q □□□□□□□□□□□ q 2 method: □ □ □ □□□□□□□□□ q □□□□□ q □□□□ q □□□□□□□□□□□ □□ q □□□□□□□□□ q □□□□□□□□□□□ q
The third method: □□□□□ q □□□□□ q □□□□□□□□□□ q □ □ □□□□□□□□ q □□□□□□□□□ q □□□□ q □□□□□□□□□□□□□ q
The fourth method: □□□□□ □□□□□ □□□□□□□□□ q □□□□□□□□□ q □ □ □□□□□□□□□ q □ □□□□ q □□□□□□□□□□□□□ q
The 5th method: □□□□□□ q □ □ □□□□□□□□□ q □□□□ □□□□□□□□□□□□□ q □□□□□ q □□□□□ q □□□□□□□□□□ q □ □
6th method: □□□□□□□ □ q □□□□□□□□□□ q □□□□□ q □ □ □ □ □□□□□□□□□□□□ □ Q □□□□ q □□□□□□□□□ q □ □
Seventh method: □□□□□□ q □□ q □□□□□ q □□□□□□□□□□□□ q □□□ □□□□□□□□□□ q □□□□□□□□□ q □□□□ q □□□□
Section 8: □□□□□□□ □□□ q □□□□ q □ □ □ □ □ □ □ q □ □ □ □ □ □ □ □ □ □ □ □□□□ □□□□□□□□□ q □□□□□ q □ □ □
9th method: □□□□ q □□□□□□□□□□ q □□□ □□□□ q □□□□□□□□□ □□□□□□□□□□ Q □□□ q □□□□□□□□□□□□ q □
The 10th method: □□ □□□□□□□□□□□□ q □□□ □□□□□□□□□□ q □ □□□□□□□□□□□□□ Q □□□ q □□□□□□□□□□ q □ □
11th method: □□□□ □□□□□□□□□□ q □□□ □□□□ q □□□□□□□□□□□□□ □□ q □□□ □□□□□□□ q □□□□ q □□□□□
12th method: □□□ □□□□□□□□□□□□ qq □ □ □ □ □ □ □ □ □ □□□ □□□□□□ □ □ □□□□ □ □ □ □ □ □ □□□□ q □□□□□
Section 13: □□□ □□□□□□□□□□□ q □□□□ q □□□□□ q □ □ □ □ □□□□□□□□□□□□ □ q □□ q □□□□□□□□□□□ q □ □
14th method: □ □ □ □ q □□□□□□□□□ □ q □□□□□□□□□ q □□□□ q □□□□□□□□□□□□□ □ □ □□□□□ q □□□□□ q □□□□□ 15th method: □ q □□□□□□□□□□□□ q □□□□□ q □ q □ □□□□□□□□ q □□□□□□□□□ q □ □ □ □ □ □ □ □□□□ q □□□□
The 16th method: □□□ □□□□□□□□□□□□ q □□□□□□□□□ □□□□□□□□□□ q □□□ q □□□□ □□□□□□□ q □□□□□ q □□□
17th method: □□□ □□□□□□ □□□□□□□□□□□□□ q □□□□□ □□ q □□□□□□□□ q □□ □□□□□□□ q □□□□□□□□□ q □
18th method: □□□□□□ q □□□ q □□□□□□□□□□□□ q □ □ □ □ □ □ □ □ □ □ □□□ q □□□□ □ □ □ □ □ □ □ □□□□□ q □□□□
19th method: □□□ □□□□□□ q □□□□□□□□□□□□□ q □□□□ □□□□□□□□□ □ q □□□□□ □□□□□ q □□□□□□□□□□ q □ □
The 20th method: □□□ □□□□□□□□□□ q □□□□□□□□□ q □ □ □□□□□□□□□□□□ □ q □□□□ □□□□□ q □□□□□□□□□ q □ □
21nd method: Q □□□□□□□□□□□□ q □□□□□□□□□ q □□ q □ □ □ □ □ □ □ □ □ □□□□ □ □□□□ q □□□□□□□□□□ q □□□
22nd method: □□□□ q □□□□□□ □□□□□□□□□□□□ q □□□ □□□□□□□□□□ q □ □□□□□ □ □ □ □ □ □ □ □ □ q □□□□□□
23rd method: □□□□ □□□ q □□□□□□□□□□□□□□ q □□□ q □□□□□ □□□□□□□□□□□□ □ □ □□□ q □□□□□□□□□□ q □ □
24th method: □□□□ □□□□ q □□□□□□□□□□□□□ qq □ □ □ □ □ □ □ □ □ □□□□□□□□□□ Q □□□ q □□□□□□□□□□ q □ □
25th method: □□ Q □□□□□□□□□ q □□□□□□□□□□ q □□□ □□□□ □□□□□□□□□□□□ □ q □□ q □□□□□□□□□□□ q □ □
26th method: □ □ □□□□□□□□□□ q □□□□□□□□□ qq □ □ □ □ □ □ □ □ □ q □□□□□□□□□ Q □□ q □□□□□□□□□ q □□□□
27th method: □□□ □ □□□□□□□□□ q □□□□□□□□□ q □□ □□□□□ q □□□□□□□□□□□□□ □ □□□□□□ q □□□□ q □□□□□□ 28th method: □ □ □□□□□□□□□□ q □□□□□□□□□ qq □ □ □ □□□□□□□□ q □□□□□□□□□□ q □□□□□ q □□□ q □□□□□□
29th method: □□□□ q □□□ q □□□□□□□□□□□□□□ q □□□□□ □□□□ q □□□□□□□□□□□ □ Q □ □ □□□□□□□□□ q □□□□
30th method: Q □□□□□□□□□□□ q □□□□□□□□□□ q □□□□□ q □□□□ □□□□□□□□□□□ □ Q □ □ □□□□□□□□□ q □□□□
31th method: □ q □□□□□□□□□□□ q □□□□□□□□□ q □□ □□□□□ q □□□□□□□□□□ □ □ □□□□□□□□□ q □□□□□ q □ □ □
32nd method: □□ □□□□□□□□□□ q □□□□□□□□□ q □ □ □□□□□□□□□ □□□□ q □□□□□ □□□□□□□□□ q □□□□□ q □ □ □
33th method: □□□□□ □□□□ q □□□□□□□□□ q □□□□□□□□□ qq □ □ □ □ □ □ □ □ □ □□ □□□ q □□□□□□□□□□□□ q □
34th method: □□□□□ □□□□ q □□□□□ q □□□□□□□□□□□□□ q □□□□ q □□□ q □□□□ □□□□□□ □□□□□□□□□□ q □
35th method: □□□ □□□□□□ q □ □ □ □ □ □ □ □ □□□□□□□ □ q □□□□ q □ □ □□□□□ □□□□□ q □□□□□□□□□□□ q □
36th method: □□□□□□ □□□□ q □□□□□ q □□□□□□□□□□□□ q □□□□□ q □ q □□□□□ □□□□□ q □□□□□□□□□ q □ □
Section 37: □□□□□□ □ □ □□□□□□□□□ q □ □ □ □ □ □ □ □ □ □□□ □ □ □ □ □ □ □ □ □ □□□□ q □□□□□□□□□□ q □□□
38th method: □ □ □□□□□□□□□□□ q □□ q □□□□□□□□□□□□ q □□□□ q □□ q □□□□□ □□□□□□ q □□□□□□□□□ q □ □
39th method: □□□ □□□□□□□□□□ q □□□ □□□□□□□□□□□ q □ □ □□□□□□□□□□ q □□□ Q □□□□□□□□□□□□ q □ □
The 40th method: □□ □□□□□□□□□□□□ q □□ q □ □ □ □ □ □ □ □ □ □ □□□ □ □ □ □ □ □ □ □ □ □□□ q □□□□□□□□□□□ q □□□ No. 41 method: Q □□□□□□□□□□□□ q □□□□□ q □□□□□ □□□□□ q □ q □□□□□□□□□ q □ □ □ □ □ □ □ □□□□ q □□□□□
Section 42: □ q □□□□□□□□□□□□ q □□□□□ q □□□□□□□□□ qq □ □ □ □ □ □ □ □ □ □□ □ □ □ □ □ □ □□□□ q □□□□□
The 43nd method: □□□ □□□□□□□□□□□ □ □ □□□□□□□□□□□□□□ q □□□□ q □□□ q □□□ □□□□□□□ q □□□□ q □□□□□
The 44th method: □□ □□□□□□□□□ q □□□□ q □□□□□□□□□□□□□ qq □□□□□□□□□□□□□ Q □□□□ q □□□□□□□□□ q □ □
The 45th method: □□□ □□□□ q □□□□□□□□□□□ q □□□□□□□□□ q □ □ □□□□□□□□□□□ □ □ □□□ q □□□□□□□□□□ q □ □
46th method: □□□□□ q □□□□□ □□□□□ q □ □ □ □ □ □ □ □ □ □ □□□□ q □□□□□□□□□ □ □ □ q □□□□□□□□□ q □□□□□
The 47th method: □□□□□ □□□□ q □□□□□ q □□□□□□□□□□□□□□ q □□□ q □□□□ q □□□□ □□□□□□□□□ q □□□□□ q □ □ □
Section 48: □ □□□□□□□□□□ □□□□□□□□□ q □□□□□□□□ q □□ q □□□□ q □□□□□ □□□□□□□□□ q □□□□□ q □ □ □
The 49th method: □□ □□□□□□□□□□ q □□□□ q □□□□□□□□□□□□ q □□□□□ q □□□□□ □ □ □□□□□□□□□ q □ q □□□□□□□
The 50th method: □□□ □□□□ q □□□□□□□□□□□ q □□□□□□□□□ q □□□□□ q □ □ □ q □□ □□□□□□□□□ q □ q □□□□□□
Article 51: □□□□ q □□□□□ q □□□□□ q □□□□□□□□□□□□ q □ □ □ □ □ □ □ □ □ □□□ □□□□□□ □□□□□□□□□□ q □
52th method: □□□□ q □□□□ q □□□□□□□□□ q □□□□□□□□□ □□□□□□□□□ q □□ q □□ □□□ q □□□□□□□□□□□□□ q □
53th method: □□□□□□ q □□□□ q □□□□□ q □ □ □ □ □ □ □ □ □□□□□□□□□ qq □ □ □ □ □ □□□□ q □□□□□□□□□□ □ □ 54th method: □□□□□ q □□ q □□□□□ □ □ q □□□□ q □□ □□□□□□□□□□□□ q □□□□ q □□□□□ □□□□□□□□□□ q □ □
55th method: □□□□□□ □□□ q □□□□□ q □□□□□□□□□□□□ q □□□□□□□ □ □□□□ q □□□□ q □□□□□□□□□ q □□□□
56th method: □□□□ q □□□□□□□□□ q □□ □ □ □ □ □ □ □ □ □□□□□□□□□□□ qq □ □ □ □ □ □□□□ q □□□□□□□□□□ q □ □
57th method: □ q □□□□□□□□□□□□ q □□□ q □ □ □ □ □ □ □ □ □□□□□□□ □ q □□□□ q □ □ □ □□□□□□□□□□ q □□□□
The 58th method: Q □□□□□□□□□□□□□ q □□□□ q □□□□□□□□□ q □ □ □ □ □ □ □ □ □ □□□□ □ □ □ □ □ □ □□□□□ q □□□□□
59th method: □□□□ q □□□□□□□□□ q □ Q □ □ □ □ □ □ □ q □□□□□□□□□□□ q □□□□□□ Q □□□□□ q □□□□□ q □□□□□□
The 60th method: □□ □□□□□ q □□□□□□□□□□□□□ q □□□□□ q □ □ □ □ □ □ □ □ □ □□□ □□□□□□ q □□□□□□□□□ q □ □
61th method: □□□□□ q □□□□ q □□□□□□□□□□□ q □□ □□□□□□□□□□□□ □ □□□□ q □ □ □ □□□□□□□□□□ q □□□□
62th method: □□□□ q □□□□□ q □□□□□□□□□□ □ □ □□□□□□□ □ □ □ □ □ □ □ □□□□ □ □ □ □ □ □ □□□□□ q □□□□□
63th method: □□□□□ □□ q □□□□□□□□□□□ q □□□□ □□□□□□□ □ □ □ □ □ □ q □□ □□□□□□□□□ q □□□□ q □□□□
The 64th method: □□□□□ □□□□□□ □□□□ q □□□□□□□□□□□ □□□□□□□□□ q □ □ □□□ □□□□□□□□□ q □□□ q □□□□□
The 65th method: □□ □□□□□□□□□□ q □□□ q □ □ □ □ □ □ □ □ □ □□□□□□□□□ qq □ □ □ □ □ □□□□□□□□ q □□□□ q □□□□
Section 66: □□ Q □□□□□□□□□□ q □□□□□ q □□□□ □□□□□□□□□□□ □ □ □□□□ q □□□□□□□□□ □ □ q □□□□□□ 第 第 第 方法: □ □ □□□□□□□□□ q □□□□□ q □□□□□ q □ □ □ □ □ □ □ □ □ □□□□□□□□□ q □ □□□□□□□□
The 68th method: □□□□ □□□ q □□□□□□□□□□ q □□□□□□□□□ q □ □ □ □ □ □ □ □ □ □□□ □□□□□□□□□ q □□□ q □□□□□
69th method: □□□ □ □□□□□□□□□ q □□ □□□□□□□□□□□ □□□□ q □□□□□□□□□□□□ □□ q □□ q □□□□□□□□□□□ q □
Section 70: □□□□□□ □□□□□ q □□□□□ q □□□□□ □□□□□□□□□□□□ □□□□□□□□ □□ q □ □□□□□□□□□ q □□□□
Section 71: □□□□ q □□□□□□□□□ q □□□□ q □□□□ □ □□□□□□□□ q □□□□□□□□□□□ □□ q □□□□□ q □□□ q □□□□□□
Section 72: □□□□ q □□□□□□□□□ q □ □ □□□□□□□ □ □ □□□□□ □□□□□□□□□□□□ □□ q □□□□□ q □□□□ q □□□□□
Section 73: □ □ □ □ q □□□□ q □□□□□□□□□□□ q □□□□ q □□□□ □□□□□□□□□□□□□ □□ q □ q □□□□□□□□□□ □□□
Section 74: □ □ □ □ q □□□□ □□□□□□□□□□□ q □□ q □□□□□□□□ q □□□□□□□□□□ □□ QQ □□□□□□□□□□□ q □□□
Section 75: □ □ □ □ q □□□ q □□□□□□□□□□□□ □ q □□□□□□□□□ q □□□□□□□□□ □□ q □□□□ q □□□□□ q □□□□□
Section 76: □□□ □□□□□□ q □□□□□□□□□□□ □ □□□ q □ □ □ □ □ □ □ □ □□□□□□□□ □□ QQ □□□□□□□□□□□ q □□□
Section 77: □ □ □ □□□□□ q □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□□□□ □□ q □□□□ q □□□ q □□□□□□□
Section 78: □ Q □□□□□□□□□□ q □□□□□□□□□ q □ □ □□□□□□□□ q □□□□□□□□□□□ □□ q □□□□□ q □□□□□ q □□□□
Section 79: □ Q □□□□□□□□□□ q □□□□□□□□□ q □□□□ q □□□□ □□□□□□□□□□□□ □□ q □□□□□ q □□□□ q □□□□□ 80th method: □□□ □□□□□ q □□□□□□□□□□□□ □□□□ □□ q □□□ q □□□□□□□□□□□□□ q □□□□□ q □□□□ □□□□□
Section 81: □□□□□ □□□□ q □□□□□ q □□□□□□□□□□□ □ q □□□□□ q □ □ □ □ □ □ □ □□ q □ □□□□□□□□□ q □□□□
Section 82: □ q □□□□□□□□□□□ q □□ q □□□□□□□□□□ □ □ q □□□□ □□□□□□□□□□ □□ q □□ q □□□□□□□□□ q □□□
Section 83: □□□ q □□□□□ q □□□□□ q □□□□□□□ □ □□□□ q □□ □□□□□□□□□□□□ □□ q □□□□□ q □□□□□ q □□□□
84th method: □□□ q □□□□ q □□□□□□□□□ q □ □ □ □ □ □□□□□□□□□□□ □□ q □□□□□ q □□ q □□□□□□□
Section 85: □□□□□□ q □□ q □□□□□□□□□□□ q □□□□ q □□□□□ q □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□ q □□□
Section 86: □□□□ q □□□□□□□□□ q □□ □□□□□□□□□□□□ □□□□ □□□□□ q □□□□ □ □ □ □ □ □ □ □ □□□ □□□□
87th method: □□□ □□□□□□□□□□□ □□□□□ q □□□□□ q □□□□□ q □□□□□□□□□□□□ Q □□□□□□□□□ □ q □□□□□□
Section 88: □□ □□□□□□□□□ q □□□□□□□□□ q □ □ □□□□□□□ □ □ □□□□□ q □□□ □ □ □ □ □ □ □ □ □□□□□ q □ □
Section 89: □□□□□ □□□ q □□□□□□□□□□□□ q □ □ □□□□□□□□ □ □□□□□□□□ q □ □ □ □ □ □ □ □ □□□ □□□□
The 90th method: □□ □□□□□□□□□□ q □□□ q □□□□□□□□□□□□ q □ □ □□□□□□□□□ □ □ □ □ □ □ □ □ □ □ □□□□ q □□□
The 91th method: □□ □□□□□□□□□□ q □□□ q □□□□□□□□□□ □ q □□□□□ □□□ □□□□□ □ □ □ □ □ □ □ □ □□□ □□□□