Minjeong / 6월 2주차 / 3문제 #222
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🌱WIL
🚀주간 목표 문제 수: 3개
백준 #12851. 숨바꼭질2: 그래프 / 골드4
정리한 링크: (바로가기)
🚩플로우 (선택)
MAX = 100000으로 문제에서 주어진 최대 범위를 설정한다.N, K를 입력받아 수빈이의 위치와 동생의 위치를 저장한다.dist: 각 위치까지 도달하는 최소 시간을 저장 (초기값 -1)ways: 각 위치까지 최소 시간으로 도달하는 방법의 수를 저장 (초기값 0)queue를 생성하고 시작점N을 넣는다.dist[N] = 0: 시작점은 0초에 도달ways[N] = 1: 시작 위치에는 한 가지 방법으로 도달x = queue.popleft(): 현재 위치를 꺼낸다.x - 1,x + 1,x * 20 ≤ nx ≤ 100000인 경우만 유효dist[nx] == -1이면 아직 방문하지 않은 곳이므로,dist[nx] = dist+ 1: 현재 위치에서 한 번 더 이동한 시간ways[nx] = ways[x]: 이전 위치까지 도달하는 모든 방법 수를 그대로 가져옴queue.append(nx)로 큐에 추가dist[nx] == dist+ 1이면,ways[nx] += ways[x]: 추가로 또 다른 경로가 생긴 것이므로 누적print(dist[K]): 동생 위치에 도달하는 최소 시간print(ways[K]): 해당 시간으로 동생에게 도달할 수 있는 방법 수🚩제출한 코드
💡TIL
백준 #1697. 숨바꼭질: 그래프 / 실버1
정리한 링크: (바로가기)
🚩플로우 (선택)
N, K를 입력받고 최대 크기인 100001만큼 방문 배열을 만든다.visited[N] = 0으로 시작 위치 설정N을 넣는다current를 꺼낸다current == K라면 탐색 종료current-1,current+1,current*2)를 모두 탐색visited[nx] = visited[current] + 1nx를 큐에 추가visited[K]값이 정답 (가장 빠르게 동생을 찾는 시간)🚩제출한 코드
💡TIL
백준 #20546. 기적의매매법: 구현 / 실버5
정리한 링크: (바로가기)
🚩플로우 (선택)
🚩제출한 코드
💡TIL