Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c5f29e6

Browse files
jaewon1676prove-ability
authored andcommitted
Add 220418 카펫 1개의 풀이 추가
1 parent 5023459 commit c5f29e6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

‎level-2/카펫.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,30 @@ function widthHeightPair(size) {
1212
let result = []
1313
for (let i = 1; i <= Math.sqrt(size); i++) if (size % i === 0) result.push([size / i, i])
1414
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 를 순회합니다.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /