====== John ====== ===== 풀이 ===== * 같은 색의 초콜렛을 같은 파일에 들어있는 돌이라고 바꿔서 읽으면 그냥 님게임이 된다. 다만 마지막 돌을 가져가면 이기는 노멀 님이 아니라, 마지막 돌을 가져가면 지는 미제르님이 된다. * [[ps:problems:boj:11694]]와 사실상 동일한 문제이다 * 미제르 님은 [[ps:게임 이론]]에서 설명했듯이, 모든 파일의 돌이 1일때만 파일 갯수의 홀짝여부에 따라 승패가 결정되고, 나머지 포지션에서는 노멀님과 동일한 승리조건을 갖는다. O(n)에 계산 가능하다 ===== 코드 ===== """Solution code for "BOJ 3754. John". - Problem link: https://www.acmicpc.net/problem/3754 - Solution link: http://www.teferi.net/ps/problems/boj/3754 Tags: [game theory] """ import functools import operator import sys def main(): T = int(sys.stdin.readline()) for _ in range(T): N = int(sys.stdin.readline()) A = [int(x) for x in sys.stdin.readline().split()] if max(A) == 1: print('John' if N % 2 == 0 else 'Brother') else: grundy = functools.reduce(operator.xor, A) print('John' if grundy != 0 else 'Brother') if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:골드_3 ps:teflib:linear_homogeneous_recurrence}}