Algorithm/Programmers
프로그래머스. 카펫(c++) / 완탐(Brute Force)
jungahshin
2021. 1. 8. 19:07
반응형
이것은 간단한 공식? 으로 해결할 수 있는 문제였다.
[메인 로직]
(행*열 = 갈색 수+노란색 수)이기 때문에 R*C를 통해 각 R, C의 값을 유추해볼 수 있다.
또한, (r-2)*(c-2) = 노란색 수 공식도 성립해야한다.
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
31
32
|
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int brown, int yellow) {
vector<int> answer;
int RC = brown+yellow;
int r, c;
for(int i=3; i<=RC/3; i++){
if(RC%i==0){
int a = i;
int b = RC/i;
if((a-2)*(b-2)!=yellow) continue;
if(a>=b){
c = a;
r = b;
}else{
c = b;
r = a;
}
break;
}
}
answer.push_back(c);
answer.push_back(r);
return answer;
}
|
cs |
반응형