본문 바로가기

Algorithm/프로그래머스139

[프로그래머스]힙(Heap) : 라면공장 (level 2)(c++) https://programmers.co.kr/learn/courses/30/lessons/42629 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; int solution(int stock, vector dates, vector supplies, int k) { // 최대 힙 선언(우선순위 큐) priority_queue pq; int cnt = 0; int strt = 0; // stock : 버틸 수 있는 날짜. stock의 숫자에 해당하는 날까지 버틸 수 있다. /.. 2020. 5. 14.
[프로그래머스]힙(Heap) : 더 맵게(level 2) (c++) https://programmers.co.kr/learn/courses/30/lessons/42626 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; int solution(vector scoville, int K) { // 최소 힙에 scoville 요소 담기 priority_queue pq(scoville.begin(), scoville.end()); // 힙의 최소값이 K 이상이 되면, 섞은 횟수 반환 int answer = 0; while (!pq.empty() &.. 2020. 5. 13.
[프로그래머스]2020 KAKAO BLIND RECRUITMENT : 괄호 변환 (level 2)(c++) https://programmers.co.kr/learn/courses/30/lessons/60058 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; // 문자열의 앞뒤를 자르고 괄호 반전 string make_reverse_except_ft(const string &u) { string tmp = u.substr(1, u.size() - 2); for (char &c : tmp) { c = ((c == '(') ? ')' : '('); } return tmp; } // 틀린 문자열 시작.. 2020. 5. 13.
[프로그래머스]2017 카카오코드 예선 : 카카오프렌즈 컬러링북 (level 2)(c++) https://programmers.co.kr/learn/courses/30/lessons/1829 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 방법 1: DFS #include #include using namespace std; int M, N; // 오른쪽, 아래쪽, 왼쪽, 위쪽 vector drx = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} }; void dfs(vector &picture, vector &cnt, int x, int y) { // 해당 색 영역 개수 + 1 ++*(cnt.end() - 1); int num .. 2020. 5. 11.