八王后

百度找的,这个程序相当“好看”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include<iostream>
using namespace std;
int main()
{
int a[9][9];
int x[9];
int n, b = 0;
n = 8;
for (int i = 0;i < n;i++)
{
for (int j = 0;j < n;j++)
a[i][j] = 0;
}
for (int c = 1;c <= n;c++)
{
x[1] = c;
a[1][c] = 1;
for (int c1 = 1;c1 <= n;c1++)
{
if (c1 != c)
a[1][c1] = 0;
}
for (int d = 1;d <= n;d++)
{
x[2] = d;
a[2][d] = 1;
for (int d1 = 1;d1 <= n;d1++)
{
if (d1 != d)
a[2][d1] = 0;
}
for (int e = 1;e <= n;e++)
{
x[3] = e;
a[3][e] = 1;
for (int e1 = 1;e1 <= n;e1++)
{
if (e1 != e)
a[3][e1] = 0;
}
for (int f = 1;f <= n;f++)
{
x[4] = f;
a[4][f] = 1;
for (int f1 = 1;f1 <= n;f1++)
{
if (f1 != f)
a[4][f1] = 0;
}
for (int g = 1;g <= n;g++)
{
x[5] = g;
a[5][g] = 1;
for (int g1 = 1;g1 <= n;g1++)
{
if (g1 != g)
a[5][g1] = 0;
}
for (int h = 1;h <= n;h++)
{
x[6] = h;
a[6][h] = 1;
for (int h1 = 1;h1 <= n;h1++)
{
if (h1 != h)
a[6][h1] = 0;
}
for (int i = 1;i <= n;i++)
{
x[7] = i;
a[7][i] = 1;
for (int i1 = 1;i1 <= n;i1++)
{
if (i1 != i)
a[7][i1] = 0;
}
for (int j = 1;j <= n;j++)
{
x[8] = j;
a[8][j] = 1;
for (int j1 = 1;j1 <= n;j1++)
{
if (j1 != j)
a[8][j1] = 0;
}
if (x[1] != x[2] && x[1] != x[3] && x[1] != x[4] && x[1] != x[5] && x[1] != x[6] && x[1] != x[7] && x[1] != x[8])
{
if (x[2] != x[3] && x[2] != x[4] && x[2] != x[5] && x[2] != x[6] && x[2] != x[7] && x[2] != x[8])
{
if (x[3] != x[4] && x[3] != x[5] && x[3] != x[6] && x[3] != x[7] && x[3] != x[8])
{
if (x[4] != x[5] && x[4] != x[6] && x[4] != x[7] && x[4] != x[8])
{
if (x[5] != x[6] && x[5] != x[7] && x[5] != x[8])
{
if (x[6] != x[7] && x[6] != x[8])
{
if (x[7] != x[8])
{
if (x[1] != x[2] + 1 && x[1] != x[3] + 2 && x[1] != x[4] + 3 && x[1] != x[5] + 4 && x[1] != x[6] + 5 && x[1] != x[7] + 6 && x[1] != x[8] + 7)
{
if (x[2] != x[3] + 1 && x[2] != x[4] + 2 && x[2] != x[5] + 3 && x[2] != x[6] + 4 && x[2] != x[7] + 5 && x[2] != x[8] + 6)
{
if (x[3] != x[4] + 1 && x[3] != x[5] + 2 && x[3] != x[6] + 3 && x[3] != x[7] + 4 && x[3] != x[8] + 5)
{
if (x[4] != x[5] + 1 && x[4] != x[6] + 2 && x[4] != x[7] + 3 && x[4] != x[8] + 4)
{
if (x[5] != x[6] + 1 && x[5] != x[7] + 2 && x[5] != x[8] + 3)
{
if (x[6] != x[7] + 1 && x[6] != x[8] + 2)
{
if (x[7] != x[8] + 1)
{
if (x[1] != x[2] - 1 && x[1] != x[3] - 2 && x[1] != x[4] - 3 && x[1] != x[5] - 4 && x[1] != x[6] - 5 && x[1] != x[7] - 6 && x[1] != x[8] - 7)
{
if (x[2] != x[3] - 1 && x[2] != x[4] - 2 && x[2] != x[5] - 3 && x[2] != x[6] - 4 && x[2] != x[7] - 5 && x[2] != x[8] - 6)
{
if (x[3] != x[4] - 1 && x[3] != x[5] - 2 && x[3] != x[6] - 3 && x[3] != x[7] - 4 && x[3] != x[8] - 5)
{
if (x[4] != x[5] - 1 && x[4] != x[6] - 2 && x[4] != x[7] - 3 && x[4] != x[8] - 4)
{
if (x[5] != x[6] - 1 && x[5] != x[7] - 2 && x[5] != x[8] - 3)
{
if (x[6] != x[7] - 1 && x[6] != x[8] - 2)
{
if (x[7] != x[8] - 1)
{
b++;
cout << "--------" << b << "----------" << endl;
for (int k = 1;k <= n;k++)
{
for (int l = 1;l <= n;l++)
cout << a[k][l] << " ";
cout << endl;
}
cout << endl << endl;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
cout << "共" << b << "种。";
system("pause");
return 0;
}

作者

我是呆呆啊

发布于

2021-01-09

更新于

2021-01-09

许可协议

评论