Programmers 42842 카펫

로고 이미지

문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42842

나의 풀이

2h + 2w - 4 = brown
h * w = brown + yellow

풀이 코드 : 42842 카펫

#include <string>
#include <vector>
#include <cmath>
using namespace std;

vector<int> solution(int brown, int yellow) {
    vector<int> answer;
    int w;
    w = (((brown+4)/2) + sqrt((brown+4)*(brown+4)/4 - 4*(brown+yellow)))/2;
    int h = (brown + yellow)/w;
    answer.push_back(w);
    answer.push_back(h);
    return answer;
}

채점결과

42586


© 2020. All rights reserved.

Powered by Hydejack v8.4.0