1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 | def check(a, b, card):
if card[a] is card[b]:
return a
if card[a] is 1:
if card[b] is 2:
return b
else:
return a
elif card[a] is 2:
if card[b] is 3:
return b
else:
return a
else:
if card[b] is 1:
return b
else:
return a
def rec(st, ed, card):
if st is ed:
return st
l = rec(st, (st + ed)//2, card)
r = rec((st + ed)//2 + 1, ed, card)
return check(l, r, card)
def main():
T = int(input())
for tc in range(1, T + 1):
N = int(input())
card = list(map(int, input().split()))
print("#{} {}".format(tc, rec(0, N-1, card) + 1))
main()
|
4880. [파이썬 S/W 문제해결 기본] 5일차 - 토너먼트 카드게임
내 친구 LCS의 작성코드. 간결하고 명확하다
답글삭제