STUDY/Algorithm
[SWEA] 5656_벽돌깨기, 모의역량테스트, 못푼 문제!!
sinawi95
2021. 2. 23. 21:28
728x90
깨진건 벽돌이 아니라 내 머리다.
못풀었다. 너무 어렵다...
타인의 코드를 봐야할지, 아니면 공부를 더하고 다시 봐야할지 모르겠다.
일단 이번주 주말까지는 보류...
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import sys
from collections import deque
sys.stdin = open('../.others/5656_input.txt','r')
dq = deque()
def crush(matrix, row, col, number):
# 벽돌은 숫자 1 ~ 9 로 표현되며,
# 구슬이 명중한 벽돌은 상하좌우로 ( 벽돌에 적힌 숫자 - 1 ) 칸 만큼 같이 제거된다.
delta = [(-1, 0),(1, 0),(0, -1),(0, 1),] # 상하좌우
crush_list = deque()
for dt in delta:
tmp_r = row
tmp_c = col
cnt = 0
while cnt < number:
crush_list.append((tmp_r, tmp_c, matrix[tmp_r][tmp_c]))
matrix[tmp_r][tmp_c] = 0
tmp_r += dt[0]
if not 0 <= tmp_r < len(matrix):
break
tmp_c += dt[1]
if not 0 <= tmp_c < len(matrix[0]):
break
cnt += 1
return crush_list
def gravity(matrix, width, height):
for h in range(1, height):
for w in range(width):
if matrix[h][w] == 0 and matrix[h-1][w] != 0:
matrix[h][w] = matrix[h-1][w]
matrix[h-1][w] = 0
def check_depth(matrix, width, height, depth):
# N번째 깊이까지 확인했을때, 1이 아닌수만 확인
# 하나 명중시켰을때 터지는 계수 계산
pass
def bfs():#bfs? dfs?
pass
t = int(input())
for tc in range(1, t + 1):
# 1 ≤ N ≤ 4, 2 ≤ W ≤ 12, 2 ≤ H ≤ 15
n, w, h = map(int, input().split()); print(n,w,h)
bd = [list(map(int, input().split())) for _ in range(h)]
for _ in bd: print(_)
# N번의 기회
copy_n = n
while copy_n > 0:
# 1. 모든 column에 대해 위에서부터 N번째 안에 2이상 경우가 있다.
# 1)없으면 result = 현재벽돌수 - N, break
#
# 2)있으면 2이상 있는 w를 stack에 넣고, N을 해당 깊이 만큼 줄임
# 벽돌을 제거하고 중력 작용. (제거한 벽돌의 수 저장)
# 1. 반복.
pass
# 모든경우에서 다 끝났으면 제거한 벽돌의 수가 가장 큰 경우를 가져옴
result = 0 #가장 많이 터트리고 남은 벽돌의 수
print("#{} {}".format(tc, result))
if tc == 1: break