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
- Spring Boot
- critical rendering path
- server
- Git
- Camera Movement
- express
- Unity IAP
- screencapture
- OverTheWire
- linux
- --watch
- Packet Network
- css framework
- react
- Digital Ocean
- Google Refund
- springboot
- SDK upgrade
- Camera Zoom
- unity
- spread 연산자
- nodejs
- docker
- java
- Unity Editor
- rpg server
- Google Developer API
- mongoDB
- draganddrop
- MySQL
Archives
- Today
- Total
우당탕탕 개발일지
[프로그래머스] Level 3. 셔틀버스 본문
https://school.programmers.co.kr/learn/courses/30/lessons/17678
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
해결방법
- 먼저 대기하는 사람순으로 정렬한다.
- 셔틀버스를 앞에서부터 하나씩 크루를 태운다.
- 마지막 셔틀버스일때, 수용인원이 가득 찼다면, 맨마지막으로 탄 크루보다 1분 일찍 탄다.
- 만약 수용인원이 가득차지 않았다면, 셔틀버스가 도착한 시간에 탄다.
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
string solution(int n, int t, int m, vector<string> timetable) {
string answer = "";
vector<int> minutes;
for(int i=0; i<timetable.size(); i++){
int m = stoi(timetable[i].substr(0,2))*60 + stoi(timetable[i].substr(3,2));
minutes.push_back(m);
}
sort(minutes.begin(), minutes.end());
int ts = 9*60; //9시에 도착함.
int index = 0;
while(n>0){
//멤버수만큼
int i=0;
for(;i<m; i++){
if(index < minutes.size() && minutes[index]<=ts) index++;
else break;
}
if(n>1){
n--;
ts+=t; //도착시간증가
continue;
}
int my = 0;
if(i == m) my = minutes[index-1]-1; //인원꽉찼음.
else my = ts; //버스출발시간에 맞춰서옴.
string hourStr = my/60 <10? "0"+to_string(my/60) :to_string(my/60);
string minuteStr = my%60 <10 ? "0"+to_string(my%60) : to_string(my%60);
return hourStr+":"+minuteStr;
}
return 0;
}
'Algorithm(c++) > Level 3' 카테고리의 다른 글
[프로그래머스] Level 3. 순위 (0) | 2025.03.13 |
---|---|
[프로그래머스] Level 3. 거스름돈 (0) | 2025.03.13 |
[프로그래머스] Level 3. 가장 긴 팰린드롬 (0) | 2025.03.10 |
[프로그래머스] Level 3. 디스크 컨트롤러 (0) | 2025.03.09 |
[프로그래머스] Level 3. 입국 심사 (0) | 2025.03.09 |