●문제


●입출력

사용 알고리즘 : 완전탐색
문제해석 : 갈색(brow), 과 노랑색(yellow)가 주어졌을때 갈색으로 둘러쌓인 노란색 도형을 만들때
나올수있는 가로 세로 값을 return
푼방법 : 전체넓이를 구한다
전체넓이 = 갈색 + 노란색
가로 길이는 세로 길이보다 같거나 길기때문에 세로는 최소 3칸이 되어야지만 조건을 충족함
( 가로 - 2 ) + (세로 - 2) 는 노란색이다
#include <string>
#include <vector>
#include <cmath>
using namespace std;
vector<int> solution(int brown, int yellow)
{
int area = brown + yellow;
for (int height = 3; height <= sqrt(area); height++)
{
if (area % height == 0)
{
int width = area / height;
if ((width - 2) * (height - 2) == yellow)
{
return { width, height };
}
}
}
return {};
}
점수 : 1
레벨 : 2
'C++ 프로그래머스 > Exhaustive search' 카테고리의 다른 글
| 프로그래머스(C++) - 최소 직사각형 (0) | 2025.08.29 |
|---|---|
| 프로그래머스(C++) - 피로도 (0) | 2025.08.29 |
| 프로그래머스(C++) - 소수 찾기 (0) | 2025.08.26 |
| Algorithm - Exhaustive search (완전탐색) (0) | 2025.08.26 |
