-
Notifications
You must be signed in to change notification settings - Fork 5
Hongjoo/8월 2주차 / 2문제 #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hongjoo/8월 2주차 / 2문제 #246
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
045df3a
Merge pull request #230 from AlgorithmStudy-Allumbus/YoonYn9915_prese…
YoonYn9915 50de6cd
[PGS]#42627. 디스크컨트롤러/lv3/3hours
zaqquum 5938cf5
[PGS]#42628. 우선순위큐/lv3/40min
zaqquum 8346319
[PGS]#42627. 디스크컨트롤러/lv3/3hours
zaqquum 8326392
Upload W28(06.23.2025)
zaqquum af30442
[BOJ]#11723. 집합/실버5/30min
zaqquum df3fb18
[PGS]#12953. N개의 최소공배수/lv2/1h(힌트)
zaqquum bbaa8e8
[PGS]#42746. 가장 큰수/lv2/1h(힌트)
zaqquum 4d3c4b5
[PGS]#42577. 전화번호 목록/lv2/실패
zaqquum 6f01f3c
[PGS]#81302. 거리두기 확인하기/lv2/1h20min(힌트)
zaqquum 6db6e68
[BOJ]#2468. 안전영역/실버1/1h 12min
zaqquum 24e1242
[BOJ]#6603. 로또/실버2/45min
zaqquum eefc145
[BOJ]#16987. 계란으로계란치기/골드5/실패
zaqquum 7bdf288
[BOJ]#1230.. 문자열거리/골드1/실패
zaqquum c7cb402
[BOJ]#1158. 요세푸스문제/실버4/20min
zaqquum f4562e9
[BOJ]#28066. 타노스는 요세푸스가 밉다/실버2/50min
zaqquum 79092b9
[BOJ]#2644. 촌수계산/실버2/20min
zaqquum bd24e68
[BOJ]#5014. 스타트링크/실버1/23min
zaqquum a5813c0
Merge branch 'main' into hongjoo
Mingguriguri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """ | ||
| [BOJ] 스타트링크/ 실버1 | ||
|
|
||
| - 총 f 층, 현위치 s 층 , 목적지 G층 | ||
| - 이동 방법 (1) 위로 U 층 , (2) 아래로 D 층 | ||
| - 출력 : 최소 버튼 횟수 (불가능하면 "use the staris") | ||
| - 1 <= s , g <= f <= 10^6 | ||
| #FLOW : 최단 거리 = BFS | ||
| 1. 총 0 ~f 층 방문 배열 생성(미방문 조건 -> 최단 거리 확보) | ||
| 2. BFS 진행 | ||
| - qeueu : [현 위치하는 층수 ] , 방문 여부 visited[층수] = 버튼 횟수(: -1) | ||
| - 탐색 범위 : 1 <= nn <= f | ||
| """ | ||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
|
|
||
| total_floors , cp , tp , up , down = map(int, input().split()) | ||
|
|
||
|
|
||
| def bfs(start, end , total_floors, up , down): | ||
| building = [-1 for _ in range(total_floors+1)] | ||
| #1. 시작 위치 start 의 초기화 | ||
| q = deque([start]) | ||
| building[start] = 0 | ||
| #2. bfs 탐색 | ||
| while q : | ||
| cn = q.popleft() | ||
| cbutton = building[cn] | ||
| # pruning 조건 : | ||
| if cn == end : | ||
| break | ||
| for dh in [up , -down] : # 엘베 2가지 조작 방법 :up , down | ||
| nn = cn + dh | ||
| # 다음 층이 건물 층수 범위내에 존재함& 미방문=> 방문하기 | ||
| if 1 <= nn <= total_floors and building[nn] <0 : | ||
| q.append(nn) | ||
| building[nn] = cbutton +1 | ||
| return building[end] | ||
|
|
||
|
|
||
| answer=bfs(cp , tp , total_floors , up , down) | ||
| #3. 출력 형식 지정 | ||
| if answer < 0 : | ||
| print("use the stairs") | ||
| else : | ||
| print(answer) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """ | ||
| [BOJ] #2644. 촌수계산 / 실버2 | ||
|
|
||
| 할아버지 - 아빠 - 나 | ||
| 할아버지 - 그외 기타 등등 | ||
| - 촌수 = X <-> Y 까지 거리 | ||
| """ | ||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
| #1. 입력 변수 | ||
| # 인접 리스트 만들기(양방향) | ||
|
|
||
| N = int(input()) | ||
| nodes = [[] for _ in range(N+1)] | ||
| tx , ty = map(int, input().split()) | ||
|
|
||
|
|
||
| M = int(input()) | ||
| for _ in range(M): | ||
| x,y= map(int,input().split()) | ||
| nodes[x].append(y) | ||
| nodes[y].append(x) | ||
|
|
||
| # 2.x -> y 의 최단 거리 찾기 : BFS | ||
| # 거리 = level | ||
| q = deque([[tx , 0] ]) | ||
| visited = [] | ||
| answer = -1 | ||
| while q : | ||
| cn , cl = q.popleft() | ||
| if cn == ty : # target 값에 도달할때만 촌수를 answer에 업데이트 하기 | ||
| answer = cl | ||
| break | ||
| for nn in nodes[cn]: # 인접 리스트 찾기 | ||
| if nn not in visited : | ||
| visited.append(nn) | ||
| q.append([nn ,cl+1] ) | ||
|
|
||
|
Comment on lines
+31
to
+40
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 dfs로 풀긴 했는데 bfs로 풀어도 로직 자체는 비슷한 것 같네요! |
||
| # print(visited) | ||
| print(answer) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2가지 조작법이라 전 각각 따로 처리하긴 했는데 for loop 도는 게 더 깔끔한 것 같네요!