# a = int(input())# b = 0# if a <= 500:# b = a * 70 / 100# elif 500 < a and a <= 1500:# b = 350 + (a - 500) * 40 / 100# elif 1500 < a and a <= 4500:# b = 750 + (a - 1500) * 15 / 100# elif 4500 < a and a <= 10000:# b = 1200 + (a - 4500) * 5 / 100# else :# b = 1475 + (a - 10000) * 2 / 100# print('%.0f' %b)# x = input()# s = 0# for i in range(1, len(x)):# if x[i-1] == x[i]:# s += 5# else :# s += 10# print(s + 10)# a = int(input())# sum = 0# for i in range(a):# x, y = input().split()# x = int(x)# y = int(y)# n = y % x# sum += n# print(sum)# n = int(input())# m = int(input())## ls = []# check = 0# check_ls = []## for i in range(n):# v = []# for j in range(n):# v.append(0)# ls.append(v)## for i in range(m):# x, y = map(int, input().split())# ls[x-1][y-1] = 1# ls[y-1][x-1] = 1### def f(x):# global check# for k in range(n):# if ls[x][k] == 1:# if check_ls.__contains__(x) == False or check_ls.__contains__(k) == False:# check += 1# check_ls.append(x)# check_ls.append(k)# f(k)## f(0)# print(check)# check = 1# ls = []## for i in range(7):# s = input().split()# v = []# for j in range(7):# v.append(int(s[j]))# ls.append(v)##### def find(x, y, c):# ls[x][y] = 0# global check# if x >= 1:# if ls[x-1][y] == c:# check += 1# find(x-1, y, c)# if x <= 5:# if ls[x+1][y] == c:# check += 1# find(x+1, y, c)# if y >= 1:# if ls[x][y-1] == c:# check += 1# find(x, y-1, c)# if y <= 5:# if ls[x][y+1] == c:# check += 1# find(x, y+1, c)### s = 0## for i in range(7):# for j in range(7):# if ls[i][j] != 0:# find(i, j, ls[i][j])# if check >= 3:# s += 1# check = 1## print(s)# A = 0## ls = []# n = int(input())# for i in range(n):# v = []# for j in range(n):# v.append(100)# ls.append(v)## xK, yK = map(int, input().split())# xK -= 1# yK -= 1# x0, y0 = map(int, input().split())# x0 -= 1# y0 -= 1## def f(x, y, cnt):# global A# if A == 0:# if x !=x0 or y != y0:# ls[x][y] = cnt# if x >= 2 and y >= 1:# if ls[x-2][y-1] > cnt+1:# f(x-2, y-1, cnt+1)## if x >= 1 and y >= 2:# if ls[x - 1][y - 2] > cnt + 1:# f(x - 1, y - 2, cnt+1)## if x < n-2 and y < n-1:# if ls[x + 2][y + 1] > cnt + 1:# f(x + 2, y + 1, cnt+1)## if x < n-1 and y < n-2:# if ls[x + 1][y + 2] > cnt + 1:# f(x + 1, y + 2, cnt+1)## if x < n-1 and y >= 2:# if ls[x - 1][y - 2] > cnt + 1:# f(x - 1, y - 2, cnt+1)## if x < n-2 and y >= 1:# if ls[x + 2][y - 1] > cnt + 1:# f(x + 2, y - 1, cnt+1)## if x >= 1 and y < n-2:# if ls[x - 1][y + 2] > cnt + 1:# f(x - 1, y + 2, cnt+1)## if x >= 2 and y < n-1:# if ls[x - 2][y + 1] > cnt + 1:# f(x - 2, y + 1, cnt+1)# else:# A += 1# ls[x0][y0] = cnt# cnt = 0# else:# if cnt == 0:# for i in range(n):# for j in range(n):# ls[i][j] = 0# elif x != x0 or y != y0 and cnt < ls[x0][y0]:# if x >= 2 and y >= 1:# f(x - 2, y - 1, cnt + 1)## if x >= 1 and y >= 2:# f(x - 1, y - 2, cnt + 1)## if x < n - 2 and y < n - 1:# f(x + 2, y + 1, cnt + 1)## if x < n - 1 and y < n - 2:# f(x + 1, y + 2, cnt + 1)## if x < n - 1 and y >= 2:# f(x - 1, y - 2, cnt + 1)## if x < n - 2 and y >= 1:# f(x + 2, y - 1, cnt + 1)## if x >= 1 and y < n - 2:# f(x - 1, y + 2, cnt + 1)## if x >= 2 and y < n - 1:# f(x - 2, y + 1, cnt + 1)# elif x == x0 and y == y0:# ls[x0][y0] = cnt# cnt = 0## f(xK, yK, 0)## print(ls[x0][y0])#ls = []n = int(input())for i in range(n): v = [] for j in range(n): v.append(668) ls.append(v)xK, yK = map(int, input().split())xK -= 1yK -= 1x0, y0 = map(int, input().split())x0 -= 1y0 -= 1def f(x, y, cnt): if x !=x0 or y != y0: ls[x][y] = cnt if x >= 2 and y >= 1: if ls[x-2][y-1] > cnt+1: f(x-2, y-1, cnt+1) if x >= 1 and y >= 2: if ls[x - 1][y - 2] > cnt + 1: f(x - 1, y - 2, cnt+1) if x < n-2 and y < n-1: if ls[x + 2][y + 1] > cnt + 1: f(x + 2, y + 1, cnt+1) if x < n-1 and y < n-2: if ls[x + 1][y + 2] > cnt + 1: f(x + 1, y + 2, cnt+1) if x < n-1 and y >= 2: if ls[x + 1][y - 2] > cnt + 1: f(x + 1, y - 2, cnt+1) if x < n-2 and y >= 1: if ls[x + 2][y - 1] > cnt + 1: f(x + 2, y - 1, cnt+1) if x >= 1 and y < n-2: if ls[x - 1][y + 2] > cnt + 1: f(x - 1, y + 2, cnt+1) if x >= 2 and y < n-1: if ls[x - 2][y + 1] > cnt + 1: f(x - 2, y + 1, cnt+1) else: if ls[x0][y0] > cnt: ls[x0][y0] = cntf(xK, yK, 0)print(ls[x0][y0])
top of page
기능을 테스트하려면 라이브 사이트로 이동하세요.
2024.01.14
2024.01.14
댓글 0개
좋아요
댓글(0)
bottom of page