꼼꼼히 천천히 구현했다~
사 방향을 일일이 코드로 짜서 좀 긴데ㅠ, 줄일 수 있을 것 같기도 하다.
🧐 헷갈렸던 부분
- 이미 넘어진 격자의 도미노를 공격수가 무너뜨리려고 할 때는 공격수 점수를 카운트 하면 안된다!
- x, y, d 는 map(int,input().split())으로 하면 안되는데 해서, 잠깐 에러를 만났다.. d는 숫자가 아니고 알파벳이다..
- 다시 도미노를 쌓을 때는, 원래 가지고 있던 높이 만큼 쌓아줘야 하므로 그 높이를 origin_height에 copy.deepcopy를 이용해서 저장해뒀다.
👩💻 코드
import sys, collections, copy
input = sys.stdin.readline
N, M, R = map(int, input().split())
game_map = list(list(map(int, input().split())) for _ in range(N))
origin_height = copy.deepcopy(game_map)
attacker_score = 0
for _ in range(R): # 라운드
# 공격수의 행동
x, y, d = input().split()
domino = collections.deque()
x, y = int(x) - 1, int(y) - 1
domino.append((x, y, game_map[x][y]))
while domino:
i, j, height = domino.popleft()
idx = 0
while idx < height:
if d == 'E':
if j + idx < M:
if game_map[i][j + idx] != 0:
domino.append((i, j + idx, game_map[i][j + idx]))
attacker_score += 1
game_map[i][j + idx] = 0
else:
break
elif d == 'W':
if 0 <= j - idx:
if game_map[i][j - idx] != 0:
domino.append((i, j - idx, game_map[i][j - idx]))
attacker_score += 1
game_map[i][j - idx] = 0
else:
break
elif d == 'S':
if i + idx < N:
if game_map[i + idx][j] != 0:
domino.append((i + idx, j, game_map[i + idx][j]))
attacker_score += 1
game_map[i + idx][j] = 0
else:
break
elif d == 'N':
if 0 <= i - idx:
if game_map[i - idx][j] != 0:
domino.append((i - idx, j, game_map[i - idx][j]))
attacker_score += 1
game_map[i - idx][j] = 0
else:
break
idx += 1
# 수비수의 행동
x1, y1 = map(int, input().split())
x1 -= 1
y1 -= 1
game_map[x1][y1] = origin_height[x1][y1]
print(attacker_score)
for i in range(N):
for j in range(M):
if game_map[i][j] == 0:
print('F', end=' ')
else:
print('S', end=' ')
print()
728x90
'즐거운 PS 👩💻🥰' 카테고리의 다른 글
[백준-파이썬] 14698: 전생했더니 슬라임 연구자였던 건에 대하여 (Hard) (0) | 2022.02.27 |
---|---|
[백준-파이썬] 16441: 아기돼지와 늑대 (0) | 2022.02.25 |
[백준-파이썬] 17619: 개구리 점프 (0) | 2022.02.21 |
[백준-파이썬] 21202: Conquest (0) | 2022.02.20 |
[백준-파이썬] 1715: 카드 정렬하기 (0) | 2022.02.20 |