Skip to content

Commit 1cb8b5a

Browse files
committed
algo study
1 parent e1514ca commit 1cb8b5a

11 files changed

+473
-284
lines changed

playGround.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a = 1
2+
print((1+2)%4)

test.py

+106-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,106 @@
1-
test = [1,2,3,4,5,6,7,8,9]
2-
l = len(test)
3-
ll = l//2
4-
5-
p = test[ll:]
6-
for i in range(0,ll):
7-
print(test[i])
8-
print(p)
1+
from collections import deque
2+
n,m,k = list(map(int,input().split()))
3+
table = [list(map(int,input().split())) for _ in range(n)]
4+
person = []
5+
for _ in range(m):
6+
a,b = list(map(int,input().split()))
7+
person.append([a-1,b-1])
8+
pl = len(person)
9+
a,b = list(map(int,input().split()))
10+
exit = [a-1,b-1]
11+
12+
dx = [-1,0,0,1]
13+
dy = [0,-1,1,0]
14+
15+
def transCoord(x,y,dist):
16+
nx = dist - x
17+
ny = y
18+
return [ny,nx]
19+
20+
def calAbs(x,y):
21+
ex,ey = exit
22+
return (abs(ex-x) + abs(ey-y))
23+
24+
def checkPerson():
25+
ex,ey = exit
26+
dist = 0
27+
while True:
28+
dist += 1
29+
for i in range(-dist,dist+1,1):
30+
for j in range(-dist,dist+1,1):
31+
if i == 0 and j == 0:
32+
continue
33+
nex,ney = ex+i,ey+j
34+
if [nex,ney] in person:
35+
return (nex,ney,dist)
36+
37+
def getRec(i,j,dist):
38+
ex,ey = exit
39+
rx,ry = 1e9,1e9
40+
if ex <= i:
41+
rx = i-dist
42+
else:
43+
rx = ex-dist
44+
if ey <= j:
45+
ry = j - dist
46+
else:
47+
ry = j - dist
48+
return (rx,ry,dist)
49+
50+
def rot(i,j,dist):
51+
global exit,person
52+
rec = [k[j:j+dist+1] for k in table[i:i+dist+1]]
53+
newRec = []
54+
print('b4',exit)
55+
print('b4',person)
56+
newPerson = []
57+
newExit = [-1,-1]
58+
for k in range(i+dist+1):
59+
temp = []
60+
for l in range(j+dist,j-1,-1):
61+
if table[l][k] == 0:
62+
if [l,k] in person:
63+
nl,nk = transCoord(l,k,dist)
64+
newPerson.append([nl,nk])
65+
elif [l,k] == exit:
66+
nl,nk = transCoord(l,k,dist)
67+
newExit = [nl,nk]
68+
temp.append(0)
69+
else:
70+
now = rec[l][k]
71+
if now > 0:
72+
now -= 1
73+
temp.append(now)
74+
newRec.append(temp)
75+
if newPerson:
76+
person = newPerson[:]
77+
if newExit:
78+
exit = newExit
79+
print(rec)
80+
print(newRec)
81+
print("after",exit)
82+
print("after",person)
83+
84+
def personMove(x,y):
85+
now = calAbs(x,y)
86+
for i in range(4):
87+
nx,ny = x+dx[i], y+dy[i]
88+
if 0<=nx<n and 0<=ny<n and table[nx][ny] == 0:
89+
new = calAbs(nx,ny)
90+
if new < now:
91+
return [nx,ny]
92+
return [-1,-1]
93+
94+
time = 0
95+
while time < 1:
96+
time += 1
97+
for i in range(pl):
98+
x,y = person[i]
99+
nx,ny = personMove(x,y)
100+
if nx == -1:
101+
continue
102+
else:
103+
person[i] = [nx,ny]
104+
a,b,c = checkPerson()
105+
a,b,c = getRec(a,b,c)
106+
rot(a,b,c)

0 commit comments

Comments
 (0)