https://programmers.co.kr/learn/courses/30/lessons/42583
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
| 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 | #include <string> #include <vector> #include <queue> using namespace std; int solution(int bridge_length, int weight, vector<int> truck_weights) {     queue<int> q;     vector<int> pos(truck_weights.size());     int sum_weight = 0, idx = 0, tm = 0;     while (!q.empty() || idx < truck_weights.size())     {         tm++;         if (!q.empty())         {             // 위치 이동             for (int i = q.front(); i <= q.back(); i++)             {                 pos[i]++;             }             // 다리 바깥으로 나올때             if (pos[q.front()] >= bridge_length)             {                 sum_weight -= truck_weights[q.front()];                 q.pop();             }         }         // 다리위 트럭 무게 + 이번 트럭 무게 <= weight --> push         if (idx < truck_weights.size() && sum_weight + truck_weights[idx] <= weight)         {             sum_weight += truck_weights[idx];             q.push(idx);             idx++;         }     }     return tm; } Colored by Color Scripter | 
기능개발 문제와 비슷하다고 생각했지만,
기능개발은 시간만 카운팅하면 되고
이번 문제는 시간, 위치까지 카운팅 해야했다.
전체 트럭개수 만큼만 for문을 돌려보려했지만 실패했다 ㅜㅜ
'Algorithm > 프로그래머스' 카테고리의 다른 글
| [프로그래머스]완전탐색 : 소수 찾기 (level 2)(c++) (2) | 2020.04.30 | 
|---|---|
| [프로그래머스]연습문제 : 124 나라의 숫자 (level 2) (c++) (0) | 2020.04.30 | 
| [프로그래머스]스택/큐 : 쇠막대기 (level 2)(c++) (0) | 2020.04.29 | 
| [프로그래머스]스택/큐 : 탑 (level 2) (c++) (0) | 2020.04.29 | 
| [프로그래머스]스택/큐 : 기능개발 (level 2) (c++) (0) | 2020.04.29 | 
댓글