Repository navigation
#17 : Week4_준희이티 #18
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
Merged
#17 : Week4_준희이티 #18
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #2023-04-27-Week3-과제 | ||
| #11650_좌표 정렬하기 | ||
|
|
||
| ''' | ||
| 문제 | ||
| 2차원 평면 위의 점 N개가 주어진다. | ||
| 좌표를 x좌표가 증가하는 순으로, | ||
| x좌표가 같으면 y좌표가 증가하는 순서로 정렬한 다음 | ||
| 출력하는 프로그램을 작성하시오. | ||
|
|
||
| 입력 | ||
| 첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. | ||
| 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. | ||
| (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, | ||
| 위치가 같은 두 점은 없다. | ||
|
|
||
| 출력 | ||
| 첫째 줄부터 N개의 줄에 점을 정렬한 결과를 출력한다. | ||
| ''' | ||
|
|
||
| N = int(input()) | ||
| array = [] | ||
|
|
||
| for i in range(N): | ||
| a,b = map(int,input().split()) | ||
| array.append((a,b)) | ||
|
|
||
| array.sort() | ||
|
|
||
| for j in range(N): | ||
| print(array[j][0],array[j][1]) #a b 출력 |
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,58 @@ | ||
| #2023-04-27-Week3-과제 | ||
| #1431_시리얼 번호 | ||
|
|
||
| ''' | ||
| 문제 | ||
| 다솜이는 기타를 많이 가지고 있다. | ||
| 그리고 각각의 기타는 모두 다른 시리얼 번호를 가지고 있다. | ||
| 다솜이는 기타를 빨리 찾아서 빨리 사람들에게 연주해주기 위해서 | ||
| 기타를 시리얼 번호 순서대로 정렬하고자 한다. | ||
|
|
||
| 모든 시리얼 번호는 알파벳 대문자 (A-Z)와 숫자 (0-9)로 이루어져 있다. | ||
| 시리얼번호 A가 시리얼번호 B의 앞에 오는 경우는 다음과 같다. | ||
|
|
||
| A와 B의 길이가 다르면, 짧은 것이 먼저 온다. | ||
|
|
||
| 만약 서로 길이가 같다면, | ||
| A의 모든 자리수의 합과 B의 모든 자리수의 합을 비교해서 | ||
| 작은 합을 가지는 것이 먼저온다. (숫자인 것만 더한다) | ||
|
|
||
| 만약 1,2번 둘 조건으로도 비교할 수 없으면, | ||
| 사전순으로 비교한다. 숫자가 알파벳보다 사전순으로 작다. | ||
| 시리얼이 주어졌을 때, 정렬해서 출력하는 프로그램을 작성하시오. | ||
|
|
||
| 입력 | ||
| 첫째 줄에 기타의 개수 N이 주어진다. | ||
| N은 50보다 작거나 같다. | ||
| 둘째 줄부터 N개의 줄에 시리얼 번호가 하나씩 주어진다. | ||
| 시리얼 번호의 길이는 최대 50이고, 알파벳 대문자 또는 숫자로만 이루어져 있다. | ||
| 시리얼 번호는 중복되지 않는다. | ||
|
|
||
| 출력 | ||
| 첫째 줄부터 차례대로 N개의 줄에 한줄에 하나씩 | ||
| 시리얼 번호를 정렬한 결과를 출력한다. | ||
| ''' | ||
|
|
||
| #익명 함수 호출을 위한 lambda / 정렬을 위한 sort 사용 가능 | ||
|
|
||
| import sys | ||
|
|
||
| #N = int(input()) | ||
| N = int((sys.stdin.readline())) | ||
|
|
||
| a = [] | ||
|
|
||
| for i in range(N) : | ||
| a.append(sys.stdin.readline()) | ||
|
|
||
| def sum (x) : | ||
| sum = 0 | ||
| for i in x : | ||
| if (x>='0') and (x<='9') : | ||
| sum += int(x) | ||
| return sum | ||
|
|
||
| a = sorted(list, key= lambda x: (len(x), sum(x), x)) | ||
|
|
||
| for i in a : | ||
| print(i) |
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,72 @@ | ||
|
|
||
| #2023-05-04-Week3-과제 | ||
| #2579_계단 오르기 | ||
|
|
||
|
|
||
| import sys | ||
| input = sys.stdin.readline | ||
|
|
||
| n = int(input()) #계단 개수 | ||
| score = [0 for i in range(301)] #계단 점수 리스트 -> 계단의 개수 300이하의 자연수 | ||
| dynamic = [0 for i in range(301)] #동적 계획법 리스트 -> 계단의 개수 300이하의 자연수 | ||
|
|
||
| for i in range(n) : | ||
| score[i] = int(input()) #계단 개수만큼 점수 입력 | ||
|
|
||
| ''' | ||
| 마지막 도착 계단은 반드시 밟아야 함 | ||
| -> 계단 개수 입력 값이 a일 때 | ||
| 마지막 도착 계단인 a번 계단을 x번째 차례에 밟은 계단이라고 하면 | ||
| x-1번째 차례에는 a-1번 계단이나 a-2번 계단을 밟았을 것 | ||
| -> a-1번 계단을 밟았다면 a-2번째 계단은 밟을 수 없음 | ||
|
|
||
| 해당 인덱스번째 계단까지의 최댓값을 | ||
| 동적 계획법 리스트에 저장 | ||
|
|
||
| i번 계단까지 최댓값 | ||
| = i-2번 계단까지 점수를 고려한 최댓값 + i번 계단의 점수 , | ||
| i-3번 계단까지 점수를 고려한 최댓값 + i-1번 계단의 점수 | ||
| 중 더 큰 값 (max로 비교) | ||
| ''' | ||
|
|
||
| dynamic[0] = score[0] | ||
| dynamic[1] = score[0] + score[1] | ||
| dynamic[2] = max (score[1]+score[2], score[0]+score[2]) | ||
|
|
||
| for i in range(3,n): | ||
| dynamic[i] = max(dynamic[i-3]+score[i-1]+score[i], dynamic[i-2]+score[i]) | ||
| print(dynamic[n-1]) | ||
|
|
||
|
|
||
| ########################################################################################### | ||
| #미리 리스트의 공간을 모두 할당 받는(?)건 낭비인가? 싶어서 다시 작성해봤지만 런타임에러 뜸 | ||
|
|
||
| import sys | ||
| input = sys.stdin.readline #이렇게 해도 런타임에러 발생 | ||
|
|
||
| n = int(input()) #계단 개수 | ||
| score = [] #계단 점수 리스트 -> 계단 개수만큼만 할당 | ||
| for x in range(n) : | ||
| score.append(int(input())) | ||
| dynamic = [] #동적 계획법 빈 리스트 | ||
|
|
||
| if n == 1: | ||
| dynamic.append(score[0]) | ||
| print(dynamic[0]) | ||
| elif n == 2 : | ||
| dynamic.append(max(score[0]+score[1], score[1])) | ||
| print(sum(score)) | ||
| else : # n >= 3 | ||
| ''' | ||
| dynamic[0] = score[0] | ||
| dynamic[1] = score[0] + soore[1] | ||
| for i in range(2,n): | ||
| dynamic[i] = max(dynamic[i-3]+score[i-1]+score[i], dynamic[i-2]+score[i]) | ||
| print(score[-1]) | ||
|
|
||
| ''' | ||
| dynamic.append(max(dynamic[i-2]+score[i] , dynamic[i-3]+score[i]+score[i - 1])) | ||
|
|
||
| print(dynamic[-1]) #마지막으로 저장한 값 출력 -> d[n-1] == d[-1] == d.pop() | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
공간복잡도를 해결해보려는 시도 아주 좋은 시도 같습니다!👍 이 문제는 리스트를 모두 0으로 할당해주어야 런타임에러가 나지 않습니다! 문제에서 주어진 입력 크기가 작기 때문에 공간복잡도보다 시간복잡도를 더 중요시 여기면 좋을 거 같습니다! 수고하셨습니다!❤️