Post

[Programmers] #120845 - 주사위의 개수 [Java][C++][Python]

[Programmers] #120845 - 주사위의 개수 [Java][C++][Python]

문제 링크


1. 아이디어

한 변이 $n$인 정육면체 주사위를 직육면체 상자에 최대한 많이 넣는 문제다. 주사위를 상자와 평행하게 넣으므로 가로, 세로, 높이 각 방향으로 길이를 $n$으로 나눈 몫만큼 한 줄로 놓을 수 있고, 세 방향이 서로 영향을 주지 않아 이 세 몫을 곱한 것이 최대 개수다.


2. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
class Solution {
    public int solution(int[] box, int n) {
        return (box[0] / n) * (box[1] / n) * (box[2] / n);
    }
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;

int solution(vector<int> box, int n) {
    return (box[0] / n) * (box[1] / n) * (box[2] / n);
}
1
2
def solution(box, n):
    return (box[0] // n) * (box[1] // n) * (box[2] // n)

This post is licensed under CC BY 4.0 by the author.