-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJD_Migong.py
61 lines (51 loc) · 1.51 KB
/
JD_Migong.py
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
import sys
def Fx(x,y,step):
next = [[0,1],[1,0],[0,-1],[-1,0]]
if x==finalx and y ==finaly:
if step<min:
min = step
flag=1
return
def main_(n,m,x=0,y=0,a=[]):
mim = 9999999
step = 0
flag = 0
next = [[0, 1], [1, 0], [0, -1], [-1, 0]]
for k in range(3):
tx = x + next[k][0]
ty = y + next[k][1]
if tx<1 or tx>n or ty<1 or ty>m:
continue
if a[tx][ty] == '.' and book[tx][ty] ==0:
book[tx][ty] = 1
Fx(tx,ty,step+1)
book[tx][ty] = 0
def HeFa(input_list=[]):
temp_list = [[0,0],[0,0]]
temp_list[0][0] = input_list
temp_list[0][1] = input_list
temp_list[1][0] = input_list
temp_list[1][1] = input_list
def Pinjie_Migong(migong=[]):
result = []
for i in range(len(migong)):
temp_migong = migong[i]
if __name__ == "__main__":
T = int(sys.stdin.readline().strip())
nm = []
migong = [[] for i in range(T)]
for i in range(T):
line_0 = sys.stdin.readline().strip()
list_0 = list(map(int,line_0.split(' ')))
nm.append(list_0)
print(nm)
for j in range(nm[i][0]):
temp = sys.stdin.readline().strip()
temp_l = list(temp.split(' '))
migong[i].append(temp_l)
startx,starty,finalx,finaly = 1,1,1,1
book = []
book[startx][starty] = 1
Fx[startx,starty,0]
for i in range(T):
main_(nm[i][0],nm[i][1],)