-
Notifications
You must be signed in to change notification settings - Fork 1
[W2] 회의실 배정 #6
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
base: main
Are you sure you want to change the base?
[W2] 회의실 배정 #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| ''' | ||
| 문제 풀이 1 | ||
| 1. 입력받은 N을 이용해서 배열 B를 제작한다. | ||
| 1.1 1-N까지의 값을 반복문을 이용해 제작. | ||
| 2. B를 오름차순 정렬한다. | ||
| 3. B[k]를 구한다. -> 어차피 배열이니까 Index값으로 뽑으면 되는데 왜 이진 탐색인거지? | ||
|
|
||
| 결과: 메모리초과 | ||
| ''' | ||
|
|
||
| n = int(input()) | ||
| k = int(input()) | ||
|
|
||
| b=sorted([i*j for i in range(1,n+1) for j in range(1,n+1)]) | ||
| print(b[k]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ''' | ||
| 문제 풀이 2 | ||
| 1. 숫자의 개수 = N*N | ||
| 2. (숫자의 개수)/2 와 K를 비교해 배열의 크기를 절반으로 축소 | ||
| 2.1 K가 클 경우 배열 = (1 ~ N) * ((N/2)+1 ~ N) | ||
| 2.2 K가 작을 경우 배열 = (1 ~ N) * ((1~(N/2+나머지)) | ||
| 3. 남은 숫자의 개수 = ((N/2)+1) * N개 | ||
| 4. 반복하며 범위 축소 | ||
| 4.1 언제까지? 시작인덱스와 종료인덱스가 같을때까지 | ||
|
Comment on lines
+4
to
+9
Owner
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. |
||
|
|
||
| 결과: 값이 정렬되지 않은 상태여서 정렬된 값을 구할 수 없음 | ||
| ''' | ||
| import math | ||
|
|
||
| n = int(input()) | ||
| k = int(input()) | ||
|
|
||
| startIndex = 1 | ||
| endIndex = n | ||
| number= n*n # 숫자의 개수 | ||
|
|
||
| while startIndex != endIndex: | ||
| isAboveMid = (number/2)<=k #16 | ||
| if isAboveMid: startIndex += math.ceil((endIndex-startIndex)/2) | ||
| else: endIndex = sum(divmod(endIndex, 2)) # K가 같거나 작을 경우의 배열 | ||
|
Owner
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. 혹시 이 코드는 어떤 역할을 하는 지 알 수 있을까요? |
||
| number = (endIndex-startIndex+1)*n | ||
|
|
||
| b = [i*j for i in range(1,n+1) for j in range(startIndex,endIndex+1)] | ||
| index = k-(n*n-n) # (endIndex-1) = 현재 선택된 행 이전의 행 -> *n을 하여 앞의 숫자 개수를 계산해서 k에서 빼준다. | ||
| print(b[index]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ''' | ||
| 풀이 방식 | ||
| 1. 종료시간으로 정렬 | ||
| 1.1 종료시간으로만 정렬했다가 실패. -> 1순위는 종료시간, 2순위는 시작시간으로 정렬해줘야했음 | ||
| 2. 예약 배열에 예약된 시간을 넣어줌 | ||
| 3. 이때, 신청 시작시간이 최근 예약된 시간의 종료시간 이후일 경우 예약 확정 | ||
| ---------- | ||
| 예제 입력1(1.1에 해당하는 예시) | ||
| 5 | ||
| 3 3 | ||
| 1 2 | ||
| 2 3 | ||
| 3 4 | ||
| 4 5 | ||
| ''' | ||
| n = int(input()) | ||
| schedule = sorted([list(map(int, input().split())) for _ in range(n)],key=lambda time: (time[1],time[0])) | ||
| print(schedule) | ||
|
Owner
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. 이건 디버깅 코드인가요? 아니면 아직 이 코드가 통과가 안 된 상태인가요? |
||
| reservation=[schedule[0]] | ||
| for time in schedule[1:]: | ||
| if time[0]>=reservation[-1][1]:reservation.append(time) | ||
|
Comment on lines
+19
to
+21
Owner
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. 스터디 때 제 코드 설명드리면서 언급했던 아이디어인데, 가장 늦은 종료 시간을 변수에 담아 업데이트 하는 방식은 어떠신가요? 재사용되지 않는 데이터라 메모리 측면에서 비효율적인 것 같습니다. 한 번 고려해주시면 감사하겠습니다! |
||
|
|
||
| print(len(reservation)) | ||

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.
ㅋㅋ