(SW 문제해결 응용 구현 - 탐욕 알고리즘) SWEA 5203 - 베이비진 게임
10 Aug 2019 | Algorithm SWEA문제
- SWEA 5203 - [파이썬 S/W 문제해결 구현 3일차] 탐욕 알고리즘 - 베이비진 게임
- 문제링크
- 문제의 저작권은 SW Expert Academy에 있습니다.
나의 코드
TC = int(input())
for tc in range(1, TC+1):
Data = list(map(int, input().split()))
flag = False
cnt = 0
for index in range(6, 13, 2):
result = []
for i in range(2):
Deck = [Data[x] for x in range(i, index,2)]
cnt_lst = [0] * 12
for j in range(len(Deck)):
cnt_lst[Deck[j]] += 1
k = 0
Tri = Run = 0
while k < 10:
if cnt_lst[k] >= 3:
cnt_lst[k] -= 3
Tri += 1
continue
if cnt_lst[k] >= 1 and cnt_lst[k + 1] >= 1 and cnt_lst[k + 2] >= 1:
cnt_lst[k] -= 1
cnt_lst[k + 1] -= 1
cnt_lst[k + 2] -= 1
Run += 1
continue
k += 1
cnt += 1
if Tri > 0 or Run > 0:
result.append(1)
else:
result.append(0)
if (result[0] == 1 and result[1] == 1) or (result[0] == 2 and result[1] == 2) :
flag = True
print('#%d'%(tc), 1)
break
elif result[0] > result[1]:
flag = True
print('#%d'%(tc), 1)
break
elif result[0] < result[1]:
flag = True
print('#%d'%(tc), 2)
break
if flag:
continue
else:
print('#%d'%(tc), 0)