늘
완전탐색_카펫 본문
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
'알고리즘_프로그래머스 > 기타 문제' 카테고리의 다른 글
타겟 넘버 (0) | 2021.05.18 |
---|---|
괄호 회전하기(월간 코드 챌린지 시즌2) Lv.2 (0) | 2021.04.20 |
해시_전화번호 목록 (0) | 2021.03.28 |
탐욕법(Greedy)_구명보트 (0) | 2021.03.22 |
탐욕법(Greedy)_조이스틱 (0) | 2021.03.18 |
Comments