Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

Life Engineering

[프로그래머스] 카펫 (C++) 본문

Problem Solving

[프로그래머스] 카펫 (C++)

흑개 2021. 10. 21. 15:46

https://programmers.co.kr/learn/courses/30/lessons/42842?language=cpp 

 

코딩테스트 연습 - 카펫

Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과

programmers.co.kr

#include <string>
#include <vector>

using namespace std;

vector<int> solution(int brown, int yellow) {
    vector<int> answer;
    int sero=1;
    int garo=((brown+4)/2)-sero;
    while (garo>=sero){
        if (garo*sero==brown+yellow){
            answer.push_back(garo);
            answer.push_back(sero);
            break;
        }
        sero++;
        garo=((brown+4)/2)-sero;
    }
    return answer;
}

연립방정식에 기반한 완탐문제.