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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define pii pair<int,int > 
 
 
 
string solution(int n, int t, int m, vector<string> time) {
    vector<int> ti;
    for(int i=0;i<time.size();i++){
        int hour=stoi(time[i].substr(0,2));
        int min=stoi(time[i].substr(3,2));
        ti.push_back(hour*60+min);
    }
    sort(ti.begin(),ti.end());
   
    int start=9*60;
    int answer=0;
    int pos=0;
    for(int i=0;i<n;i++){
        int cnt=0;
        start=(9*60)+(i*t);
        bool chk=false;
        
          
        while(pos<ti.size()){
            if(ti[pos]<=start){
                cnt++;
                pos++;
                if(cnt==m)
                    break;
            }
            else
                break;
        }
        if(i==n-1){
            if(cnt==m) answer=ti[pos-1]-1;
            else answer=start;
        }
    }
    string ans="";
    int hour=answer/60;
    int min=answer%60;
    if(hour<10){
        ans="0"+to_string(hour);
    }else{
        ans+=to_string(hour);
    }
    ans+=":";
    if(min<10){
        ans+="0"+to_string(min);
    }else{
        ans+=to_string(min);
    }
    return ans;
}
cs

출처: https://school.programmers.co.kr/learn/courses/30/lessons/17678

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

조건을 단순화시키면 2가지 경우밖에없다.

1.마지막셔틀버스에 탄 승객이 꽉찬경우에는 마지막탄 승객의 시간-1분

2.마지막셔틀버스에 탄 승객이 꽉차지않은 경우에는 셔틀버스의 마지막 운영시간

문제를 단순화시키는 것이 어려운 문제였다. 

 

'알고리즘 > 프로그래머스' 카테고리의 다른 글

[c++] 야근 지수  (1) 2022.09.23
[c++] 양궁대회 (DFS,완전탐색 택1)  (0) 2022.09.21
[c++] 보석 쇼핑  (1) 2022.09.20
[c++] 숫자게임  (1) 2022.09.20
[c++] 등굣길  (0) 2022.09.19

+ Recent posts