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
- 프로토타입 중복처리
- 동적 데커레이터
- 프로토타입
- 팩터리 메서드
- 함수형 팩터리
- 컴포지트 패턴
- 동적 데코레이터
- 추상 팩터리
- 그루비 스타일 빌더
- 브릿지 패턴
- 컴포지트
- 프로토타입 패턴
- 흐름식 빌더
- 단순한 빌더
- 싱글턴
- 팩터리 패턴
- 싱글톤 패턴
- 내부 팩터리
- 빌더 패턴
- 빌더
- 싱글턴 패턴
- 데커레이터
- 데커레이터 패턴
- 컴포지트 빌더
- 모던C++디자인패턴
- 브릿지
- 팩터리
- 디자인패턴
- 싱글톤
- 디자인 패턴
Archives
- Today
- Total
GGym's Practice Notes
프로그래머스 Level2_ 다리를 지나는 트럭 (C++) 본문
Queue와 Pair를 이용해 구현
#include <string> // Level2_ 다리를 지나는 트럭 [큐]
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
int solution(int bridge_length, int weight, vector<int> truck_weights) {
int weightSum = truck_weights[0], idx=1, i;
queue<pair<int, int>> bridge;
bridge.push(make_pair(1, truck_weights[0]));
for(i=2;;i++){
if( bridge.front().first + bridge_length == i){
weightSum -= bridge.front().second;
bridge.pop();
}
if( idx == truck_weights.size() && bridge.empty()) return i;
if( weight >= weightSum + truck_weights[idx] && idx < truck_weights.size()){
weightSum += truck_weights[idx];
bridge.push(make_pair(i, truck_weights[idx++]));
}
}
return 0;
}
'Algorithm' 카테고리의 다른 글
프로그래머스 Level1_ 크레인 인형뽑기 게임 (C++) (0) | 2020.10.08 |
---|---|
프로그래머스 Level2_ 주식가격 (C++) (0) | 2020.10.08 |
프로그래머스 Level2_ 조이스틱 (C++) (0) | 2020.10.08 |
프로그래머스 Level2_ 스킬 트리 (C++) (0) | 2020.10.08 |
프로그래머스 Level3_ 단어 변환 (C++) (0) | 2020.10.08 |