완전탐색_카펫 본문

알고리즘_프로그래머스/기타 문제

완전탐색_카펫

giron 2021. 3. 23. 13:50
728x90

level 2였지만 쉬웠던 문제였다. 간단히 방정식만 생각하면 되었다..!

(x-2)*(y-2) = yellow
2*x+2*y-4 = brown

아마 이 수식 계산하는게 복잡해서 level2인가..? 싶다..!

#include <string>
#include <cmath>
#include <vector>

using namespace std;

vector<int> solution(int brown, int yellow) {
    vector<int> answer;
    int x, y;
    y= ((4+brown) + sqrt(pow(4+brown,2) - 8*(2*yellow + 2*brown)))/4;
    x = (yellow+brown)/y;
    
    if(x>y){
        answer.push_back(x);
        answer.push_back(y);   
    }else{
        answer.push_back(y);
        answer.push_back(x);   
    }
    
    return answer;
}
728x90
Comments