Baekjoon 17027번 [Shell Game]
https://www.acmicpc.net/problem/17027
17027번: Shell Game
The first line of the input file contains an integer $N$ giving the number of swaps ($1 \leq N \leq 100$). Each of the next $N$ lines describes a step of the game and contains three integers $a$, $b$, and $g$, indicating that shells $a$ and $b$ were swappe
www.acmicpc.net
- 사용언어: Python (PyPy3)
- 알고리즘: 구현, 시뮬레이션
문제
코드
더 좋은 방법이 있을 것 같기도 함
start_1, ans_1 = [0, 1, 0, 0], 0
start_2, ans_2 = [0, 0, 1, 0], 0
start_3, ans_3 = [0, 0, 0, 1], 0
N = int(input())
for i in range(N):
a, b, g = map(int, input().split())
start_1[a], start_1[b] = start_1[b], start_1[a]
start_2[a], start_2[b] = start_2[b], start_2[a]
start_3[a], start_3[b] = start_3[b], start_3[a]
if start_1[g] == 1:
ans_1 += 1
if start_2[g] == 1:
ans_2 += 1
if start_3[g] == 1:
ans_3 += 1
print(max(ans_1, ans_2, ans_3))
'백준 > USACO bronze 기출' 카테고리의 다른 글
[백준] 16770번 The Bucket List (0) | 2022.10.12 |
---|---|
[백준] 16769번 Mixing Milk (0) | 2022.10.12 |
[백준] 15593번 Lifeguards (Bronze) (0) | 2022.10.03 |
[백준] 14530번 The Lost Cow (0) | 2022.10.03 |
[백준] 14175번 The Cow-Signal (0) | 2022.10.03 |