https://www.acmicpc.net/problem/16918
비교적 간단한 시뮬레이션 문제
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
32
33
34
35
36
37
38
|
direction = ((-1, 0), (1, 0), (0, -1), (0, 1))
r, c, n = map(int, input().split())
MAP = [list(input()) for _ in range(r)]
time = [[-1]*c for _ in range(r)]
cnt = 0
# 초기화
for i in range(r):
for j in range(c):
if MAP[i][j] == 'O':
time[i][j] = 0
while cnt != n:
boom = []
for i in range(r):
for j in range(c):
if MAP[i][j] == '.' and time[i][j] == -1 and cnt != 0: # 0초일땐 무시
MAP[i][j] = 'O'
time[i][j] = 0
elif MAP[i][j] == 'O' and time[i][j] < 3:
time[i][j] += 1
if time[i][j] == 3:
boom.append((i,j)) # 폭발 리스트를 만들어서 터지는 폭탄 삽입
for i,j in boom:
MAP[i][j] = '.'
time[i][j] = -1
for d in direction:
ny = i + d[0]
nx = j + d[1]
if 0 <= ny < r and 0 <= nx < c:
MAP[ny][nx] = '.'
time[ny][nx] = -1
cnt += 1
for m in MAP:
print(''.join(m))
|
cs |
728x90
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[Python]16985. Maaaaaaaaaaze (0) | 2019.04.12 |
---|---|
[Python]17070. 파이프 옮기기1 (0) | 2019.04.12 |
[Python]5373. 큐빙 (0) | 2019.04.11 |
[Python]16939. 2x2x2 큐브 (0) | 2019.04.10 |
[Python]16235. 나무 재테크 (0) | 2019.04.10 |
댓글