티스토리 뷰
728x90
https://www.acmicpc.net/problem/1743
1743번: 음식물 피하기
첫째 줄에 통로의 세로 길이 N(1 ≤ N ≤ 100)과 가로 길이 M(1 ≤ M ≤ 100) 그리고 음식물 쓰레기의 개수 K(1 ≤ K ≤ N×M)이 주어진다. 그리고 다음 K개의 줄에 음식물이 떨어진 좌표 (r, c)가 주어진다
www.acmicpc.net
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
|
from collections import deque
def bfs(x, y):
global cnt
dq = deque()
dq.append((x, y))
visit[x][y] = True
while dq:
x, y = dq.popleft()
cnt += 1
for dx, dy in direction:
nx, ny = x + dx, y + dy
if 0 <= nx <= N and 0 <= ny <= M and lst[nx][ny] == 1 and not visit[nx][ny]:
dq.append([nx, ny])
visit[nx][ny] = True
N, M, K = map(int, input().split())
lst = [[0 for _ in range(M + 1)] for _ in range(N + 1)]
visit = [[False for _ in range(M + 1)] for _ in range(N + 1)]
direction = [(0, 1), (1, 0), (0, -1), (-1, 0)]
res = 0
for i in range(K):
a, b = map(int, input().split())
lst[a][b] = 1
for i in range(1, N + 1):
for j in range(1, M + 1):
cnt = 0
if lst[i][j] == 1 and not visit[i][j]:
bfs(i, j)
res = max(cnt, res)
print(res)
|
cs |

'코딩 > 파이썬 백준' 카테고리의 다른 글
백준 9935 문자열 폭발 (파이썬) (0) | 2022.02.03 |
---|---|
백준 5585 거스름돈 (파이썬) (0) | 2022.02.03 |
백준 16120 PPAP (파이썬) (0) | 2022.02.01 |
백준 1697 숨바꼭질 (파이썬) (0) | 2022.02.01 |
백준 12761 돌다리 (파이썬) (0) | 2022.02.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 백준 13335
- 백준 1351 파이썬
- 백준 9205 파이썬
- 백준 6593
- 백준 12788
- 백준 9205
- 백준 6593 파이썬
- 백준 4446 파이썬
- 백준 12034
- 백준 10825 파이썬
- 백준 12788 파이썬
- 백준 13335 파이썬
- 백준 1916
- 백준 1504 파이썬
- 백준 20362
- 백준 2075
- 백준 10825
- 백준 4446
- 백준 1351
- 백준 2304
- 백준 12034 파이썬
- 백준 23253 파이썬
- 백준 2304 파이썬
- 백준 20362 파이썬
- 백준 11123 파이썬
- 백준 1916 파이썬
- 백준 23253
- 백준 11123
- 백준 2075 파이썬
- 백준 2491 파이썬
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함