#!/usr/bin/python
ary = [0 for x in range(9)]
box = [0 for x in range(9)]
def dfs(stp):
if (stp +1 == 11):
print(box);
return
for i in range(1, 10):
if(ary[i - 1] == 0):
box[stp -1] = i
ary[i - 1] = 1
dfs(stp + 1)
ary[i - 1] = 0
def equalData(step):
if (step == 10):
if(box[0] * 100 + box[1] * 10 + box[2] + box[3] * 100 +box[4] * 10 + box[5] == box[6] * 100 + box[7] * 10 + box[8]):
print(box)
return
for i in range(1, 10):
if (ary[i - 1] == 0):
box[step - 1] = i
ary[i - 1] = 1
equalData(step + 1)
ary[i - 1] = 0
ary = [[0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0 ,0,1]]
m = 5
n = 4
dx = 4
dy = 2
mark = [[0, 0, 0, 0] for x in range(5)]
minStep = 100
def findRoad(x, y, step):
global minStep
stpNext = [[0, 1], [1, 0], [0, -1], [-1, 0]]
if (x == dx) and (y == dy):
if step < minStep:
minStep = step
print(minStep)
return
for i in range(4):
nX = x + stpNext[i][0]
nY = y + stpNext[i][1]
if (nX < 1 ) or (nY < 1) or (nX >= m) or (nY >= n):
continue
if (mark[nX][nY] == 0) and (ary[nX][nY] == 0):
mark[nX][nY] = 1
findRoad(nX, nY, step + 1)
mark[nX][nY] = 0
print(x, y)
class note:
def __init__(self, px, py, pStp):
self.x = px
self.y = py
self.stp = pStp
def set(self, px, py, pStp):
self.x = px
self.y = py
self.stp = pStp
def show(self):
print(self.x, self.y, self.stp)
def main() :
data = [2, 1, 3, 4, 5, 6, 7]
node = ListNode(data[0])
head = node
# equalData(1)
qeue = [note(0, 0, 0) for i in range(100)]
head = 1
tail = 1
qeue[tail].set(1, 1, 0)
tail += 1
print("xxxxxxxxxxxx")
flag = 0
stpDir = [[1, 0], [0, 1], [-1 , 0], [0, -1]]
while head != tail:
for drn in stpDir:
x = qeue[head].x +drn[0]
y = qeue[head].y + drn[1]
if (x < 1) or (y < 1) or (x >= m) or (y >= n):
continue
print(x, y)
if (mark[x][y] == 0) and (ary[x][y] == 0) :
qeue[tail].set(x, y, qeue[head].stp + 1)
mark[x][y] = 1
tail += 1
if (x == dx) and (y == dy):
flag = 1
break
if (flag == 1):
break
head += 1
# findRoad(1, 1, 0)
print("step is %d" %(qeue[tail - 1].stp))
if __name__ == "__main__":
main()