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
- 18249
- 유니티
- 영상 프레임 추출
- 문자열 압축
- 알고리즘
- mysqld.sock
- 3344
- 탄막 이동
- 알고리즘 목차
- 3273
- AI Hub
- 우분투
- 강의실2
- 탄막
- 수 만들기
- 백준
- 자료구조 목차
- 그리디알고리즘
- 단어 수학
- c#
- MySQL
- 탄막 스킬 범위
- 2020 KAKAO BLIND RECRUITMENT
- 토글 그룹
- 걷는건귀찮아
- SWEA
- 원형
- 마우스 따라다니기
- 윈도우
- 회의실 배정
Archives
- Today
- Total
와이유스토리
[그리디] 프로그래머스 [1차] 셔틀버스 C++ 본문
https://school.programmers.co.kr/learn/courses/30/lessons/17678
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int timeToInt(string time) {
return stoi(time.substr(0,2)) * 60 + stoi(time.substr(3,2));
}
string intToTime(int time) {
return to_string(time/60/10) + to_string(time/60%10) + ":" + to_string(time%60/10) + to_string(time%60%10);
}
string solution(int n, int t, int m, vector<string> timetable) {
sort(timetable.begin(), timetable.end());
int answer = 0;
int cnt = timetable.size();
int now = 9 * 60; // 셔틀 도착 시간, 09:00부터 n회 t 간격
int idx = 0; // 크루 대기 순서
for(int i=0; i<n; i++) {
int temp = 0; // now에 태울 수 있는 크루원 수
while (true) {
if (idx >= cnt) break;
if (temp >= m) break;
if (timeToInt(timetable[idx]) <= now) { // if문 안에 idx++
temp++;
idx++;
}
else break;
}
if (temp < m) answer = now; // m명 미만일 때, 제일 늦은 도착 시간 = 현재 시간, idx-- 대신 idx-1
else if (temp >= m) answer = timeToInt(timetable[idx-1]) - 1; // m명 이상일 때, 제일 늦은 도착시간 = 마지막 크루원 도착 시간 - 1
now += t;
}
return intToTime(answer);
}
'코딩테스트 > 그리디|힙' 카테고리의 다른 글
[그리디] 백준 8980 택배 C++ (0) | 2023.09.27 |
---|---|
[그리디] 백준 1715 카드 정렬하기 C++ (0) | 2023.09.27 |
[그리디] 백준 2839 설탕 배달 C++ (0) | 2022.02.09 |
[그리디] 백준 1931번 회의실 배정 C++ (0) | 2022.01.19 |
[그리디, 우선순위큐] 백준 1379번 강의실2 C++ (0) | 2022.01.18 |
Comments