문제 바로가기
lv2
노랑이가 들어가야 되니까..가로의 최소는 무조건 2 이상이여야 하고
노랑이 개수는 가로 - 2 * 세로 - 2 와 같다는 것을 발견해서 이걸 이용했다.
가로 세로를 경우의 수를 따져서 푸는 방법이다.
#include <string>
#include <vector>
using namespace std;
int tmp_width, tmp_height;
vector<int> solution(int brown, int yellow) {
vector<int> answer;
int halfbrown = brown / 2;
int mx_width = halfbrown % 2 == 0 ? halfbrown / 2 : (halfbrown + 1) / 2;
for(int i = 2; i <= mx_width ; i++)
{
tmp_width = halfbrown - i + 1;
tmp_height = i + 1;
if(tmp_width >= tmp_height && ((tmp_width - 2) * (tmp_height - 2) == yellow))
{
answer.push_back(tmp_width);
answer.push_back(tmp_height);
}
}
return answer;
}