Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- sortedBy
- GREEDY
- Poll
- Recursion
- Java
- 알고리즘
- PriorityQueue
- 2D Array
- heap
- Main
- programmers
- 코틀린
- foreach
- 2020
- contentToString
- report
- Kotlin
- solution
- Queue
- hackerrank
- Util
- booleanarray
- 프로그래머스
- lastIndex
- dp
- dynamic programming
- 동적계획법
- indices
- intarray
- Developer
Archives
- Today
- Total
Code in
프로그래머스 완전탐색 카펫 with Kotlin 본문
프로그래머스 완전 탐색 부분 카펫 문제입니다.
IntelliJ에서의 풀이입니다.
val brown: Int = 24 // 최소 8
val yellow: Int = 24 // 최소 1
fun solution(brown: Int, yellow: Int): IntArray {
var answer = intArrayOf()
// brown = 2*(가로+세로 - 2) yellow = 가로*세로 - brown
// (가로+세로) = brown/2 + 2
// 가로*세로 = brown + yellow
val mul: Int = brown + yellow
val sum: Int = brown / 2 + 2
// 가로 = mul/세로
// 가로+세로 = sum
var height = 3 // 최솟값
while (mul % height != 0)
height++
var width: Int = mul / height // 최댓값
while (width + height != sum) {
height++
while (mul % height != 0)
height++
width = mul / height
}
answer += width
answer += height
return answer
}
fun main() {
print(solution(brown, yellow).contentToString()) // 8, 6
}
URL: https://programmers.co.kr/learn/courses/30/lessons/42842
코딩테스트 연습 - 카펫
Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과 ��
programmers.co.kr
'알고리즘 스터디_문제풀이' 카테고리의 다른 글
프로그래머스 탐욕법(Greedy) 큰 수 만들기 with Kotlin, 테스트 케이스 추가 (1) | 2020.08.16 |
---|---|
프로그래머스 탐욕법(Greedy) 체육복 with Kotlin (0) | 2020.08.15 |
프로그래머스 완전탐색 소수 찾기 with Kotlin (1) | 2020.08.14 |
프로그래머스 완전탐색 모의고사 with Kotlin (1) | 2020.08.13 |
프로그래머스 힙 이중우선순위큐 with Kotlin (0) | 2020.08.12 |
Comments