-
Notifications
You must be signed in to change notification settings - Fork 3
AC, 절댓값 힙, 피보나치 수 5, 하노이 탑, 하노이 탑 이동 순서 #34
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
Open
ssongjay
wants to merge
7
commits into
familycourt:main
Choose a base branch
from
ssongjay:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d36c0a5
AC / 1h 7m
ssongjay 7450be0
절댓값 힙 / 27m
ssongjay 3f2b6c8
피보나치 수 5 / 3m
ssongjay 4d0214a
재귀함수가 뭔가요? / 24m
ssongjay 09cdc39
Update readme
ssongjay 30f984b
하노이 탑 / 1h 2m
ssongjay 530f3d2
하노이 탑 이동 순서 / 1m
ssongjay 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,17 @@ | ||
| # 절댓값 힙 | ||
|
|
||
| import sys | ||
| import heapq | ||
|
|
||
| N = int(sys.stdin.readline().rstrip()) | ||
| queue = [] | ||
|
|
||
| for i in range(N): | ||
| x = int(sys.stdin.readline().rstrip()) | ||
| if x != 0: | ||
| heapq.heappush(queue, (abs(x), x)) | ||
| else: | ||
| if not queue: | ||
| print(0) | ||
| else: | ||
| print(heapq.heappop(queue)[1]) |
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,32 @@ | ||
| # AC | ||
|
|
||
| import sys | ||
| from collections import deque | ||
|
|
||
| T = int(sys.stdin.readline().rstrip()) | ||
| for _ in range(T): | ||
| flag = 1; | ||
| p = sys.stdin.readline().rstrip() | ||
| n = int(sys.stdin.readline().rstrip()) | ||
| num_array = deque(sys.stdin.readline().strip()[1:-1].split(',')) | ||
| if n == 0: | ||
| num_array = deque() | ||
| for i in p: | ||
| if i == 'R': | ||
| flag *= (-1) | ||
| elif i == 'D': | ||
| if len(num_array) == 0: | ||
| print("error") | ||
| flag = 0 | ||
| break | ||
| else: | ||
| if flag == 1: | ||
| num_array.popleft() | ||
| elif flag == -1: | ||
| num_array.pop() | ||
| if flag == -1: | ||
| num_array.reverse() | ||
| print("[" + ",".join(num_array) + "]") | ||
| elif flag == 1: | ||
| print("[" + ",".join(num_array) + "]") | ||
|
|
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,15 @@ | ||
| # 피보나치 수 5 | ||
|
|
||
| import sys | ||
|
|
||
| n = int(sys.stdin.readline().rstrip()) | ||
|
|
||
| def fibo(n): | ||
| if n == 0: | ||
| return 0 | ||
| elif n == 1: | ||
| return 1 | ||
| else: | ||
| return (fibo(n - 1) + fibo(n - 2)) | ||
|
|
||
| print(fibo(n)) |
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,20 @@ | ||
| # 하노이 탑 이동 순서 | ||
|
|
||
| import sys | ||
| # 원판의 개수 N | ||
| N = int(sys.stdin.readline().rstrip()) | ||
|
|
||
| # N 홀수일 때 3에 먼저 올려야함 | ||
| # N 짝수일 때 2에 먼저 올려야함 | ||
|
|
||
| def hanoi(N, a, b, c): | ||
| if N == 1: | ||
| print(a, c, sep = " ") | ||
| else: | ||
| hanoi(N - 1, a, c, b) | ||
| hanoi(1, a, b, c) | ||
| hanoi(N - 1, b, a, c) | ||
|
|
||
| print(2**N - 1) | ||
| if(N <= 20): | ||
| hanoi(N, 1, 2, 3) |
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,37 @@ | ||
| # 재귀함수가 뭔가요? | ||
|
|
||
| import sys | ||
|
|
||
| N = int(sys.stdin.readline().rstrip()) | ||
|
|
||
| print("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.") | ||
|
|
||
| def last_print(index): | ||
| print_dot(index) | ||
| print("\"재귀함수가 뭔가요?\"") | ||
| print_dot(index) | ||
| print("\"재귀함수는 자기 자신을 호출하는 함수라네\"") | ||
| print_dot(index) | ||
| print("라고 답변하였지.") | ||
|
|
||
| def print_dot(index): | ||
| for _ in range(index): | ||
| print("____", end='') | ||
|
|
||
| def recursive(N, index): | ||
| if index >= N: | ||
| last_print(index) | ||
| else: | ||
| print_dot(index) | ||
| print("\"재귀함수가 뭔가요?\"") | ||
| print_dot(index) | ||
| print("\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.") | ||
| print_dot(index) | ||
| print("마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.") | ||
| print_dot(index) | ||
| print("그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"") | ||
| recursive(N, index + 1) | ||
| print_dot(index) | ||
| print("라고 답변하였지.") | ||
|
|
||
| recursive(N, 0); |
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,20 @@ | ||
| # 하노이 탑 | ||
|
|
||
| import sys | ||
| # 원판의 개수 N | ||
| N = int(sys.stdin.readline().rstrip()) | ||
|
|
||
| # N 홀수일 때 3에 먼저 올려야함 | ||
| # N 짝수일 때 2에 먼저 올려야함 | ||
|
|
||
| def hanoi(N, a, b, c): | ||
| if N == 1: | ||
| print(a, c, sep = " ") | ||
| else: | ||
| hanoi(N - 1, a, c, b) | ||
| hanoi(1, a, b, c) | ||
| hanoi(N - 1, b, a, c) | ||
|
|
||
| print(2**N - 1) | ||
| if(N <= 20): | ||
| hanoi(N, 1, 2, 3) |
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.
ㅎㅎ 축하드립니다.