Study hard
(c++)프로그래머스 코딩테스트 연습 - 카펫 본문
programmers.co.kr/learn/courses/30/lessons/42842
[풀이]
노란 격자의 모든 가능한 경우에 대해 노란 격자를 감싸는 테두리의 개수가 brown과 같은지 비교하는 방법으로 풀었다.
#include <string>
#include <vector>
using namespace std;
int Brown,Yellow;
vector<int>Answer;
bool getRowCol(int row, int col){
int tmp=row*2+col*2+4;
if(Brown==tmp){
Answer.push_back(row+2);
Answer.push_back(col+2);
return true;
}
return false;
}
vector<int> solution(int brown, int yellow) {
Brown=brown;
Yellow=yellow;
for(int i=1;i<=Yellow;i++){
if(Yellow/i<=i){
if(getRowCol(i,Yellow/i))
break;
}
}
return Answer;
}
'프로그래머스 > 완전탐색' 카테고리의 다른 글
(c++) 프로그래머스 코딩테스트 연습 - 소수 찾기 (0) | 2020.10.20 |
---|---|
(c++) 프로그래머스 코딩테스트 연습 - 모의고사 (0) | 2020.10.19 |