백준 문제풀이
백준 11871 - 님 게임 홀짝 [Python]
Vermeil
2021. 8. 19. 13:56
https://www.acmicpc.net/problem/11871
11871번: 님 게임 홀짝
koosaga와 cubelover가 님 게임 홀짝 버젼을 하고 있다. 님 게임은 돌을 차곡 차곡 위로 쌓아올린 돌 더미 k개를 이용한다. 각각의 돌 더미에는 한 개 이상의 돌이 있다. 두 사람은 서로 턴을 번갈아가
www.acmicpc.net
노트에 8정도까지만 써보면 규칙이 보인다. 홀수면 (i + 1) / 2, 짝수면 (i - 2) / 2이다. 모두 xor해서 승자를 찾으면 끝이다.
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
def ip(): return int(input())
def sp(): return str(input().rstrip())
def mip(): return map(int, input().split())
def msp(): return map(str, input().split().rstrip())
def lmip(): return list(map(int, input().split()))
def lmsp(): return list(map(str, input().split().rstrip()))
n = ip()
p = lmip()
ans = 0
for i in p:
ans ^= ((i + 1) // 2 if i & 1 else (i - 2) // 2)
print("koosaga" if ans else "cubelover")
|
cs |