-
[백준 문제풀이] 얼렁뚱땅 3184 양 풀이얼렁뚱땅 백준 문제풀이 2022. 9. 21. 15:58
https://www.acmicpc.net/problem/3184
3184번: 양
첫 줄에는 두 정수 R과 C가 주어지며(3 ≤ R, C ≤ 250), 각 수는 마당의 행과 열의 수를 의미한다. 다음 R개의 줄은 C개의 글자를 가진다. 이들은 마당의 구조(울타리, 양, 늑대의 위치)를 의미한다.
www.acmicpc.net
이~~~~~~~~지~~~~~~~~ 19분만에 풀어서 기분 좋은뎁쇼
from collections import deque n, m = map(int,input().split()) arr = [list(map(str,input())) for _ in range(n)] visited = [[False]*m for _ in range(n)] dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] def bfs(x_,y_) : global sheep global wolf q = deque() q.append([x_,y_]) visited[x_][y_] = True while q : x, y = q.popleft() if arr[x][y] == 'v' : wolf += 1 elif arr[x][y] == 'o' : sheep += 1 for k in range(4) : nx = x + dx[k] ny = y + dy[k] if 0<=nx<n and 0<=ny<m : if arr[nx][ny] != '#' and visited[nx][ny] == False : q.append([nx,ny]) visited[nx][ny] = True all_wolf = 0 all_sheep = 0 for i in range(n) : for j in range(m) : if visited[i][j] == False : sheep = 0 wolf = 0 bfs(i,j) if sheep > wolf : all_sheep += sheep else : all_wolf += wolf print(all_sheep, all_wolf)
'얼렁뚱땅 백준 문제풀이' 카테고리의 다른 글
[백준 문제풀이] 얼렁뚱땅 20055 컨베이어 벨트 위의 로봇 풀이 (1) 2022.09.23 [백준 문제풀이] 얼렁뚱땅 1916 최소비용 구하기 풀이 (1) 2022.09.22 [백준 문제풀이] 얼렁뚱땅 2589 보물섬 풀이 (0) 2022.09.20 [백준 문제풀이] 얼렁뚱땅 1138 한 줄로 서기 풀이 (0) 2022.09.20 [백준 문제풀이] 얼렁뚱땅 2251 물통 풀이 (0) 2022.09.19