top of page

소스 코드 제출

공개·회원 50명

rhakdns120403


def bfs() :
    global knight, target, m, l, c, k
    queue = [[knight[0], knight[1]]]
    while True :
        q = queue
        print(type(q[0]), type(q[1]), type(l[0][0]))
        if q[0]+2 < m and q[1]+1 < m and l[q[0]+2][q[1]+1] != 1 :
            queue.append([q[0]+2, q[1]+1])
            l[q[0]+2][q[1]+1] = 1
            c += 1
            if l[q[0]+2][q[1]+1] == 2 :
                break
        if q[0]+2 < m and q[1]-1 >= 0 and l[q[0]+2][q[1]-1] != 1 :
            queue.append([q[0]+2, q[1]-1])
            l[q[0]+2][q[1]-1] = 1
            c += 1
            if l[q[0]+2][q[1]-1] == 2:
                break
        if q[1]+2 < m and q[0]+1 < m and l[q[0]+1][q[1]+2] != 1 :
            queue.append([q[0]+1, q[1]+2])
            l[q[0]+1][q[1]+2] = 1
            c += 1
            if l[q[0]+1][q[1]+2] == 2 :
                break
        if q[1]+2 < m and q[0]-1 >= 0 and l[q[0]-1][q[1]+2] != 1 :
            queue.append([q[0]-1, q[1]+2])
            l[q[0]-1][q[1]+2] = 1
            c += 1
            if l[q[0]-1][q[1]+2] == 2 :
                break
        if q[0]-2 >= 0 and q[1]+1 < m and l[q[0]-2][q[1]+1] != 1 :
            queue.append([q[0]-2, q[1]+1])
            l[q[0]-2][q[1]+1] = 1
            c += 1
            if l[q[0]-2][q[1]+1] == 2 :
                break
        if q[0]-2 >= 0 and q[1]-1 >= 0 and l[q[0]-2][q[1]-1] != 1 :
            queue.append([[q[0]-2, q[1]-1]])
            l[q[0]-2][q[1]-1] = 1
            c += 1
            if l[q[0]-2][q[1]-1] == 2 :
                break
        if q[1]-2 >= 0 and q[0]+1 < m and l[q[0]+1][q[1]-2] != 1 :
            queue.append([[q[0]+1, q[1]-2]])
            l[q[0]+1][q[1]-2] = 1
            c += 1
            if l[q[0]+1][q[1]-2] == 2 :
                break
        if q[0]-1 >= 0 and q[1]-2 >= 0 and l[q[0]-1][q[1]-2] != 1 :
            queue.append([[q[0]-1, q[1]-2]])
            l[q[0]-1][q[1]-2] = 1
            c += 1
            if l[q[0]-1][q[1]-2] == 2 :
                break
    k.append(c)

c = 0
k = []
m = int(input())
knight = list(map(int, input().split()))
target = list(map(int, input().split()))
l = [[0 for _ in range(m)] for _ in range(m)]
l[knight[0]-1][knight[1]-1] = 1
l[target[0]-1][target[1]-1] = 2
for i in range(m) :
    for j in range(m) :
        bfs()
        if len(k) != 0 :
            if k[0] <= k[1] :
                k.pop(0)
            else :
                k.pop()
print(k[0])

3회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page