문제 링크입니다: https://programmers.co.kr/learn/courses/30/lessons/86491
코딩테스트 연습 - 8주차
[[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]] 120 [[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]] 133
programmers.co.kr
그리디 하게 두 변 중 긴 변을 가로로 짧은 변을 세로가 되게끔 회전을 시킨 후 (가로길이의 최대 값) * (세로 길이의 최대 값)을 곱해주면 최소 직사각형 면적을 구할 수 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int solution(vector<vector<int>> sizes) { | |
int width = 0; | |
int height = 0; | |
for (auto size : sizes) | |
{ | |
width = max(width, max(size[0], size[1])); | |
height = max(height, min(size[0], size[1])); | |
} | |
return width * height; | |
} | |
int main(void) | |
{ | |
vector<vector<int>> sizes = { | |
{60, 50}, | |
{30, 70}, | |
{60, 30}, | |
{80, 40} | |
}; | |
cout << solution(sizes) << "\n"; | |
return 0; | |
} |

개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > programmers' 카테고리의 다른 글
[Programmers] 짝지어 제거하기 (0) | 2021.09.30 |
---|---|
[Programmers] 모두 0으로 만들기 (0) | 2021.09.29 |
[Programmers] 로또의 최고 순위와 최저 순위 (0) | 2021.09.27 |
[Programmers 코딩테스트 고득점 Kit] 징검다리 (0) | 2021.09.26 |
[Programmers 코딩테스트 고득점 Kit] 입국심사 (0) | 2021.09.26 |