본문 바로가기

> 알고리즘 문제 풀이/BOJ51

***16768-Mooyo Mooyo (python, 파이썬) def new_arr(N): return [[False for i in range(10)] for _ in range(N)] N, K = map(int, input().split()) B = [list(input()) for _ in range(N)] visit = new_arr(N) visit2 = new_arr(N) dx, dy = [0, 1, 0, -1], [1, 0, -1, 0] def dfs(x, y): visit[x][y] = True result = 1 for i in range(4): xx, yy = x+dx[i], y+dy[i] if xx = N or yy = 10: continue if visit[xx][yy] or B[x][y] != B[xx][.. 2020. 10. 19.
**1012-유기농 배추 (python, 파이썬) 1번: 내가 작성한 코드 - 핵심 로직!! - (0,0)부터 (M,N)까지 방문하지 않은 곳 탐색 - 이제 지금 이곳은 방문했으니 visited = True - 만약 배추(1)가 있는 지점이면 - cnt +1 ! - 그리고 BFS 돌리기~~ (BFS) - queue에 해당 좌표를 넣고, while 반복문 안에서 현좌표와 상하좌우로 연결되는 지점을 방문한다! - 장차 지점의 위치가 0보다 작거나 경계값이면 continue - 지점을 처음 방문하고 and 배추(1)가 있다고 하면 - queue에 해당 지점의 좌표를 append! (여기서부터 또 연결된 배추무리를 찾아야하기 때문에 넣는다) T = int(input()) dx, dy = [0, 1, 0, -1], [1, 0, -1, 0] def BFS(i, j.. 2020. 10. 18.
**14620-꽃길 (python, 파이썬) - 포인트: - 전수조사(백만, 천만 정도의 시간 복잡도라면) + 방향벡터 - 2차원 배열의 좌표를 1차원으로 표현할 수 있음 -> 1차원 순서값 = x * N + y - x = 1차원 순서값 // N - y = 1차원 순서값 % N N = int(input()) C = [list(map(int, input().split())) for _ in range(N)] dx, dy = [0, 0, 1, 0, -1], [0, 1, 0, -1, 0] ans = 10000 def ck(flower_list): cost = 0 flower_occupied = [] for order in flower_list: x = order // N y = order % N if x == 0 or x == N-1 or y == 0 .. 2020. 10. 17.
*16956-늑대와 양 (python, 파이썬) R, C = map(int, input().split()) M = [list(input()) for i in range(R)] dx, dy = [0, 1, 0, -1], [1, 0, -1, 0] is_sheep = False for i in range(R): for j in range(C): if M[i][j] == 'W': for k in range(4): nx, ny = i + dx[k], j + dy[k] if nx < 0 or nx == R or ny < 0 or ny == C: continue if M[nx][ny] == 'S': is_sheep = True if is_sheep: print(0) else: print(1) for i in range(R): for j in range(C): if.. 2020. 10. 17.