원형에서 조건 따질때,
절댓값으로 해결하면 편하다는것을 기억하도록 하자는 교훈,,,
# n 입력
n = int(input())
# comb_1 입력
comb_1 = list(map(int, input().split()))
# comb_2 입력
comb_2 = list(map(int, input().split()))
# 함수들
# open_with_comb_1(a, b, c)
def open_with_comb_1(a, b, c):
# a, b, c와 comb_1[0], comb_1[1], comb_1[2] 각각의 간격이 모두 2 이내이면 통과
return (abs(comb_1[0] - a) <= 2 or abs(comb_1[0] - a) >= n-2) and \
(abs(comb_1[1] - b) <= 2 or abs(comb_1[1] - b) >= n-2) and \
(abs(comb_1[2] - c) <= 2 or abs(comb_1[2] - c) >= n-2)
# open_with_comb_2(a, b, c)
def open_with_comb_2(a, b, c):
# a, b, c와 comb_2[0], comb_2[1], comb_2[2] 각각의 간격이 모두 2 이내이면 통과
return (abs(comb_2[0] - a) <= 2 or abs(comb_2[0] - a) >= n-2) and \
(abs(comb_2[1] - b) <= 2 or abs(comb_2[1] - b) >= n-2) and \
(abs(comb_2[2] - c) <= 2 or abs(comb_2[2] - c) >= n-2)
# 설계
# cnt
cnt = 0
# 완전 탐색 시작
for i in range(1, n+1):
for j in range(1, n+1):
for k in range(1, n+1):
# 첫 번째 조합 또는 두 번째 조합으로 열리면,
if open_with_comb_1(i,j,k) or open_with_comb_2(i,j,k):
# cnt에 추가
cnt += 1
# 출력
print(cnt)
'Algorithm(CodeTree, Python) > 완전탐색1' 카테고리의 다른 글
[코드트리 자리 마다 숫자를 정하는 완전탐색] 개발자의 능력 2 python (0) | 2022.12.13 |
---|---|
[코드트리 자리 마다 숫자를 정하는 완전탐색] 숫자 카운트 python (0) | 2022.12.12 |
[코드트리 자리 마다 숫자를 정하는 완전탐색] 개발자의 능력 3 python (0) | 2022.12.11 |
[코드트리 자리 마다 숫자를 정하는 완전탐색] 한 가지로 열리는 자물쇠python (0) | 2022.12.11 |
[코드트리 구간 단위로 완전탐색] 밭의 높이를 고르게하기 python (0) | 2022.12.10 |