공부기록
셔틀버스 본문
programmers.co.kr/learn/courses/30/lessons/17678
import java.util.*;
import java.util.stream.Collectors;
import java.text.SimpleDateFormat;
class Solution {
private int make_min(String s){
String[] tmp_str = s.split(":");
int hour_to_min = Integer.parseInt(tmp_str[0]) * 60;
int min_val = Integer.parseInt(tmp_str[1]);
return hour_to_min + min_val;
}
private String min_to_str(int minute){
int hours = minute/60;
int left_min = minute%60;
String hour_str = Integer.toString(hours);
String min_str = Integer.toString(left_min);
if(hour_str.length() == 1)
hour_str = "0" + hour_str;
if(min_str.length() == 1)
min_str = "0" + min_str;
return hour_str + ":" + min_str;
}
public String solution(int n, int t, int m, String[] timetable) {
String answer = "";
Arrays.sort(timetable);
Vector<Integer> crews[] = new Vector[n];
for(int i=0; i<n; i++)
crews[i] = new Vector<Integer>();
int cur_row = 0;
int cursor = 0;
while(cur_row < n && cursor < timetable.length){
int tmp_min = make_min(timetable[cursor]);
if(timetable[cursor].equals("23:59")){
cursor++;
}
else if(60*9+cur_row*t >= tmp_min && crews[cur_row].size() < m){
crews[cur_row].add(tmp_min);
cursor++;
}else{
cur_row++;
}
}
for(int i=0; i<n; i++){
for(int j=0; j<crews[i].size(); j++)
System.out.print(crews[i].get(j) + " ");
System.out.println();
}
if(crews[n-1].size() < m)
answer = min_to_str(9*60 + (n-1)*t);
else
answer = min_to_str(crews[n-1].get(m-1)-1);
// int candidate_1 = 24*60;
// int candidate_2 = 24*60;
// for(int i=n-1; i>=0; i--)
// if(crews[i].size() < m){
// candidate_1 = 9*60 + i*t;
// break;
// }
// Vector<Integer> tmp_v = new Vector<>();
// if(crews[n-1].size() < m)
// candidate_2 = 60*9+t*(n-1);
// else{
// for(int i=0; i<n; i++)
// for(int j=0; j<crews[i].size(); j++)
// tmp_v.add(crews[i].get(j));
// int cur_val = tmp_v.get(tmp_v.size()-1);
// for(int i=tmp_v.size()-2; i>=0; i--){
// if(cur_val > tmp_v.get(i)){
// candidate_2 = tmp_v.get(i);
// break;
// }
// }
// }
// if(candidate_1 == 24*60 && candidate_2 == 24*60)
// answer = min_to_str(tmp_v.get(0) - 1);
// else if(candidate_2 == 24*60)
// answer = min_to_str(candidate_1);
// else if(candidate_1 == 24*60)
// answer = min_to_str(candidate_2);
// else
// answer = min_to_str(Math.max(candidate_1, candidate_2));
return answer;
}
}
/*
패배의 원인
그냥 제일 늦게오는 사람들보다 1분만 먼저오면 되는데 왜 앞사람과 같이 오면 된다고 생각을 했을까요.
사소한 실수가 사람을 잡았다.
*/
"""