File tree 1 file changed +27
-1
lines changed
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -12,4 +12,30 @@ function widthHeightPair(size) {
12
12
let result = [ ]
13
13
for ( let i = 1 ; i <= Math . sqrt ( size ) ; i ++ ) if ( size % i === 0 ) result . push ( [ size / i , i ] )
14
14
return result
15
- }
15
+ }
16
+
17
+ //정답 2 - jaewon1676
18
+ function solution ( brown , yellow ) {
19
+ var answer = [ ] ;
20
+ let sum = brown + yellow ;
21
+
22
+ //카펫의 최소높이는 3부터이다.(테두리 갈색, 가운데 노란색)
23
+ for ( let height = 3 ; height < brown / 2 ; height ++ ) {
24
+ //전체 크기에서 높이로 나눌때 나머지가 없을경우만 진행
25
+ if ( sum % height === 0 ) {
26
+ //가로길이
27
+ let weight = sum / height ;
28
+ //테두리를 제외한 길이를 구해야하기 때문에 각각 -2해준뒤 곱셈 하여 답을 구한다.
29
+ if ( ( height - 2 ) * ( weight - 2 ) === yellow ) {
30
+ return [ weight , height ] ;
31
+ }
32
+ }
33
+ }
34
+ return answer ;
35
+ }
36
+ // 완전탐색
37
+
38
+ // 문제 설명에서의 중앙은 노란색, 테두리는 갈색이 포인트입니다.
39
+ // 갈색은 항상 노란색의 가로 세로 크기보다 +2 만큼 큽니다.
40
+ // 따라서 높이는 전체 테두리/2보다 작으므로
41
+ // 3부터 brown/2 를 순회합니다.
You can’t perform that action at this time.
0 commit comments