목차

Cow Checkers

ps
링크acmicpc.net/…
출처BOJ
문제 번호5981
문제명Cow Checkers
레벨플래티넘 3
분류

게임 이론

시간복잡도O(T)
인풋사이즈T<=1000
사용한 언어Python 3.11
제출기록33376KB / 44ms
최고기록44ms
해결날짜2023/07/11

풀이

코드

"""Solution code for "BOJ 5981. Cow Checkers".

- Problem link: https://www.acmicpc.net/problem/5981
- Solution link: http://www.teferi.net/ps/problems/boj/5981

Tags: [game theory]
"""

import math
import sys

PHI = (1.0 + math.sqrt(5)) / 2.0
PHI_SQ = PHI * PHI


def main():
    # pylint: disable=unused-variable
    M, N = [int(x) for x in sys.stdin.readline().split()]
    T = int(sys.stdin.readline())
    for _ in range(T):
        X, Y = [int(x) for x in sys.stdin.readline().split()]
        x, y = sorted((X, Y))
        k = math.ceil(x / PHI)
        is_win_pos = (int(k * PHI), int(k * PHI_SQ)) != (x, y)
        print('Bessie' if is_win_pos else 'Farmer John')


if __name__ == '__main__':
    main()