Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9140977

Browse files
committed
Lv5_셔틀버스
1 parent c1472fb commit 9140977

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

‎Programmers/Lv5/Lv5_셔틀버스.cpp‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string>
4+
#include <queue>
5+
using namespace std;
6+
7+
string solution133(int n, int t, int m, vector<string> timetable) {
8+
string answer = "";
9+
int currtime = 0;
10+
int currbus = 1;
11+
int go = 0;
12+
13+
int start = 540;
14+
priority_queue<int, vector<int>, greater<int>> wait; // 빨리 온 순으로 정렬
15+
16+
for (int i = 0; i < timetable.size(); i++) {
17+
int hour = (timetable[i][0] - '0') * 10 + (timetable[i][1]-'0');
18+
int minute = (timetable[i][3] - '0') * 10 + (timetable[i][4] - '0');
19+
wait.push(hour * 60 + minute);
20+
}
21+
22+
23+
while (currbus<=n) {
24+
if (wait.empty()) { // 대기자가 없을 때
25+
currtime = 540 + t * (n - 1); // 제일 마지막차 타기
26+
break;
27+
}
28+
else { // 대기자가 있을 때
29+
if (start < wait.top()) { // 탈 수 없는 대기자라면
30+
if (currbus == n) { // 이 버스 막차면 타야함
31+
currtime = 540 + t * (n - 1);
32+
break;
33+
}
34+
// 새로운 버스 오라고 하자
35+
start += t;
36+
++currbus;
37+
go = 0;
38+
}
39+
else { // // 탈 수 있는 대기자라면
40+
if (go == m - 1 && currbus == n) { // 내가 꼭 타야하는 상황..
41+
currtime = wait.top() - 1; // 얘보다 1분 일찍오면 탐
42+
break;
43+
}
44+
wait.pop();
45+
++go;
46+
}
47+
}
48+
49+
if (go == m) { // 버스 꽉찼으면 버스 보내자
50+
start += t;
51+
++currbus;
52+
go = 0;
53+
}
54+
}
55+
56+
if (currtime / 60 >= 10)
57+
answer += to_string(currtime / 60);
58+
else {
59+
answer += "0";
60+
answer += to_string(currtime / 60);
61+
}
62+
answer += ":";
63+
64+
if (currtime % 60 >= 10)
65+
answer += to_string(currtime % 60);
66+
else {
67+
answer += "0";
68+
answer += to_string(currtime % 60);
69+
}
70+
71+
return answer;
72+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /