반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- level2
- 백준
- dfs
- 에라스토테네스의 체
- 딕셔너리
- 가상메모리
- 파이썬
- level0
- 그리디
- 힙
- BOJ
- 수학
- python
- 다익스트라
- 스택
- 프로그래머스
- programmers
- level3
- 코딩테스트
- DP
- level1
- 브루트포스
- 가상메모리 관리
- BFS
- 재귀
- 다이나믹 프로그래밍
- 운영체제
- 구현
- N과M
- MYSQL
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level3 [ [1차] 셔틀버스] 파이썬 본문
반응형
https://programmers.co.kr/learn/courses/30/lessons/17678
코딩테스트 연습 - [1차] 셔틀버스
10 60 45 ["23:59","23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59"] "18:00"
programmers.co.kr
# 프로그래머스 [1차] 셔틀버스
from collections import deque
def solution(n, t, m, timetable):
answer = ''
bus_time = []
bus_cnt = [[] for _ in range(n)]
for i in range(n):
bus_time.append(540+i*t)
for i in range(len(timetable)):
a, b = map(int, timetable[i].split(':'))
timetable[i] = a*60+b
timetable.sort()
i = 0
j = 0
cnt = 0
while i < len(timetable) and j < n:
if timetable[i] <= bus_time[j]:
cnt += 1
bus_cnt[j].append(timetable[i])
if cnt == m:
cnt = 0
j += 1
else:
while j < n:
if timetable[i] <= bus_time[j]:
break
j += 1
cnt = 1
if j < n:
bus_cnt[j].append(timetable[i])
i += 1
if len(bus_cnt[n-1]) != m:
answer = bus_time[n-1]
else:
answer = bus_cnt[n-1][m-1]-1
H = answer//60
M = answer % 60
answer = str(H).rjust(2, '0')+':'+str(M).rjust(2, '0')
return answer
bus_time에 각 버스의 시간을 분으로 변환하여 저장한다.
timetable에 각 사람의 정류장 도착시간을 분으로 변환하여 저장한다.
bus_cnt에는 각 시간 버스당 태울 수 있는 사람의 정보 (정류장 도착시간)을 저장한다.
각 버스에 도착하는 사람을 순서대로 버스에 태우고, 다 차면 다음 버스를 태운다.
반응형
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level1 [성격 유형 검사 하기] 파이썬 (0) | 2022.09.03 |
---|---|
프로그래머스 level3 [보석 쇼핑] 파이썬 (0) | 2022.04.21 |
프로그래머스 level3 [N으로 표현] 파이썬 (0) | 2022.04.13 |
프로그래머스 level3 [하노이의 탑] 파이썬 (0) | 2022.04.11 |
프로그래머스 level3 [줄 서는 방법] 파이썬 (0) | 2022.04.11 |