:link:문제 링크

[30786 홀수 찾아 삼만리]

:question:문제 설명

좌표들이 존재하고 좌표간 거리를 $ x_1-x_2 + y_1-y_2 $ 로 정의할 때 좌표를 한번씩 방문하면서 이동 거리의 합이 홀수가 될 수 있는지 구하는 문제

:pencil2:코드

import sys
input = sys.stdin.readline


N = int(input())
even = []
odd = []
for i in range(1, N + 1):
    x, y = map(int, input().split())
    if (x + y) % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

even_cnt = len(even)
odd_cnt = len(odd)
if even_cnt == 0 or odd_cnt == 0:
    print("NO")
else:
    print("YES")
    for x in even:
        print(x, end=" ")
    for x in odd:
        print(x, end=" ")

:memo:풀이

각 좌표의 $x$와 $y$좌표 합의 홀짝성을 판별해서 홀수인 좌표들이 없거나 짝수인 좌표들이 없으면 이동거리의 합이 홀수가 안됨!!

이 문제도 대회문제였는데 대회때는 왜자꾸 겁을 많이 먹는지 모르겠다..ㅠㅠ

댓글남기기