카펫의 안이 노란색이라는 점과 테두리 1줄만 갈색이라는 점을 보면 쉽게 풀리는 문제.
(가로+세로+2)*2 == brown
의 식만 알아챈다면 빠르게 풀 수 있는 문제.2중 for문
을 사용해줬는데, 그냥 ++
--
를 사용해서 하나씩 해줘도 괜찮을 것 같다. #include <string>
#include <vector>
using namespace std;
vector<int> solution(int brown, int yellow) {
vector<int> answer;
int col = 1, row = yellow;
while(true)
{
if((row+col+2)*2==brown)
{
answer.push_back(row+2);
answer.push_back(col+2);
break;
}
for(int i=col+1;i<=yellow/2;i++)
if(yellow%i==0)
{
col = i;
row = yellow/i;
break;
}
}
return answer;
}