접근 방법
Only one combination of the orientation exists for every orientation of the first block.
Thus, for each of the six first-block-orientation, sum up the max value of each "floor", then find the ultimate max value amongst the six sums.
최종 입력 코드
import sys
n = int(sys.stdin.readline())
tower = []
down_up_dic = {0:5, 1:3, 2:4, 3:1, 4:2, 5:0}
for i in range(n):
tower.append(list(map(int, input().split())))
max_alpha = 0
for j in range(6):
max_beta = 0
first_dice = [1,2,3,4,5,6]
down_num = tower[0][j]
up_num = tower[0][down_up_dic[j]]
first_dice.remove(down_num)
first_dice.remove(up_num)
max_beta += (max(first_dice))
for k in range(1,n):
next_dice = [1,2,3,4,5,6]
down_index = tower[k].index(up_num)
up_index = down_up_dic[down_index] #계속 업데이트됨 durng for 구문
down_num = tower[k][down_index]
up_num = tower[k][up_index]
next_dice.remove(down_num)
next_dice.remove(up_num)
max_beta += max(next_dice)
if max_alpha < max_beta:
max_alpha = max_beta
print(max_alpha)
- down_up_dic를 dictionary 말고 list로 했어도 가능했을 것 같음
- max_alpha를 for loop가 진행됨에 따라 업데이트함
문제 유형: bruteforcing, implementaion | 브루트포스, 구현
문제 출처: 한국정보올림피아드 KOI 2003 초등부 2번, hwww.acmicpc.net/problem/2116
'Python > 문제풀이' 카테고리의 다른 글
python_백준BOJ_#2309_일곱 난쟁이_review (0) | 2023.01.31 |
---|---|
python_백준BOJ_#2596_비밀편지_review (0) | 2023.01.30 |