https://school.programmers.co.kr/learn/courses/30/lessons/42842

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#include <string>
#include <vector>
#include<cmath>
#include<iostream>
using namespace std;
struct ySqure{
    int width;
    int height;
};

vector<int> solution(int brown, int yellow) {
    vector<int> answer;
    //노랑의 경우의수를 전부 구해야함
    //즉 가로>=세로
    vector<ySqure>ysqure;
    int h=1;
    int w=yellow;
    for(int i=1;i<=yellow;i++){
        ySqure tmp;
        if(yellow%i==0){
            
           w=yellow/i;
           tmp.width=yellow/i+2;
           
           
           if(i==1){
              h=1;
              tmp.height=h+2;
           }else{
              h=i;
              tmp.height=h+2;
           }
 
            if(tmp.width<tmp.height){
              break;
            }
           ysqure.push_back(tmp); 
        }
     
    }
    //갈색
    for(int i=0;i<ysqure.size();i++){
        if(brown==(ysqure[i].width)*2+(ysqure[i].height-2)*2){
            answer.push_back(ysqure[i].width);
            answer.push_back(ysqure[i].height);
        }
    }
   
    return answer;
}

'알고리즘 공부' 카테고리의 다른 글

백준- 말이되고픈원숭이  (0) 2023.06.28
백준 - 미로찾기  (0) 2023.06.28
프로그래머스 소수 찾기  (0) 2023.05.10
프로그래머스 게임 맵 최단거리  (0) 2023.03.30
GBC  (0) 2023.03.02

+ Recent posts