-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_algorithm
More file actions
41 lines (35 loc) · 858 Bytes
/
Copy pathPython_algorithm
File metadata and controls
41 lines (35 loc) · 858 Bytes
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
# NOTE 1 八皇后问题
MAX = 8
queuePos = [0,0,0,0,0,0,0,0]
global sumType
sumType = 0
def pritnOut():
print "___________________________________"
for x in xrange(MAX):
for j in xrange(MAX):
if queuePos[x] == j :
print "1 ",
else:
print "0 ",
print"\n"
def isVaild(idx):
for x in xrange(idx):
if queuePos[x] == queuePos[idx]:
return 0
if (abs( queuePos[x] - queuePos[idx]) == (idx-x)):
return 0
return 1
def addQueue(idx):
for x in xrange(MAX):
if idx == MAX:
global sumType
sumType = sumType + 1
pritnOut()
return
queuePos[idx] = x
validValue = isVaild(idx)
if ( validValue == 1):
addQueue(idx+1)
if __name__ == '__main__':
addQueue(0)
print sumType