Skip to content

Commit

Permalink
알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Feb 11, 2021
1 parent 7b8d819 commit 7ffd08c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Empty file added argorithm/marble_finding2617.py
Empty file.
58 changes: 58 additions & 0 deletions argorithm/puyopuyo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from collections import deque

# BFS 함수
def bfs(x, y):
queue = deque()
temp = set()
queue.append((x, y))

while queue:
qx, qy = queue.popleft()
if (qx, qy) in temp:
continue
temp.add((qx, qy))
for i in range(4):
sx, sy = qx+dx[i], qy+dy[i]
if not(0<=sx<n and 0<=sy<m):
continue
if arr[qx][qy] == arr[sx][sy]:
queue.append((sx, sy))
return temp

# 떨어뜨리는 함수
def fall():
for i in range(n-1, -1, -1):
for j in range(m):
if arr[i][j] == '.':
for s in range(i-1, -1, -1):
if arr[s][j] != '.':
arr[i][j] = arr[s][j]
arr[s][j] = '.'
break


# 메인 함수
if __name__ == '__main__':
answer = 0
n, m = 12, 6
arr = list(list(input()) for _ in range(12))
dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1]

while True:
check = 0
for i in range(n):
for j in range(m):
if arr[i][j]=='.': continue
result = bfs(i, j)
if len(result) >= 4:
if check == 0:
check = 1
for x, y in result:
arr[x][y] = '.'
fall()
if check == 1:
answer += 1
else:
break
print(answer)

0 comments on commit 7ffd08c

Please sign in to comment.