Last active
March 9, 2018 03:55
-
-
Save qkreltms/d73c20602a822ebc1dc447ee5ec44703 to your computer and use it in GitHub Desktop.
백준 소프트콘 1회 A번 문제 https://www.acmicpc.net/problem/15501
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f(n, a, b): | |
d = [0] * n | |
dd = [0] * n | |
a_start_position = a.index(1) | |
for i in range(n): | |
j = a_start_position + i # | |
d[i] = a[j % n] - a[(j + 1) % n] # 현재 값과 다음 값의 차를 구해주는 점화식 | |
b_start_position = b.index(1) | |
for i in range(n): | |
j = b_start_position + i | |
dd[i] = b[j % n] - b[(j + 1) % n] | |
if d == dd: | |
print("good puzzle") | |
return | |
dd.reverse() | |
for i in range(n): | |
dd[i] *= -1 | |
if d == dd: | |
print("good puzzle") | |
return | |
print("bad puzzle") | |
return | |
f(int(input()), list(map(int, input().split())), list(map(int, input().split()))) | |
---------------------------설명 ------------------- | |
1. a배열의 1을 기준으로, a[n] - a[n+1] ..의 값을 d에 저장 | |
예 : 1, 2, 3, 4 는 -1, -1, -1, 3 (*마지막은 처음과 계산) | |
2. b 배열도 1번과 같이 구한 뒤, dd에 저장 | |
예: 2,3,4,1 는 -1,-1,-1,3 | |
3. d와 dd가 같은지 비교, 같으면 good puzzle | |
4. 아니면 dd를 거꾸로해준뒤 -1을 곱하고 다시 비교, 같으면 good puzzle | |
예 4, 3, 2, 1 -> -3, 1, 1, 1(2번) -> 1,1,1,-3(4번) -> -1,-1,-1,3(4번) -> a, b 비교 | |
5. 마지막까지 아니라면 bad puzzle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment