선물1166

LJM·2023년 7월 27일
0

백준풀기

목록 보기
204/259

https://www.acmicpc.net/problem/1166

이문제 어렵다

숫자도 오버플로우 나기 쉽상이다
큰박스 넓이를 구해서 작은박스의 넓이로 나눌때
l, w, h 별로 다 따로 구해줘야 한다

이분탐색할때 종료조건을 left,right를 사용하지 않고 for문으로 해야 시간초과가 나지 않는다

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");

        int n = Integer.parseInt(input[0]);
        int l = Integer.parseInt(input[1]);
        int w = Integer.parseInt(input[2]);
        int h = Integer.parseInt(input[3]);

        double left = 0;
        double right = Math.max(l, Math.max(w, h));

        for (int i = 0; i < 10000; i++) {
            double mid = (left+right)/2;
            long count = (long)(l/mid) * (long)(w/mid) * (long)(h/mid);

            if(count >= n){
                left = mid;
            }else{
                right = mid;
            }
        }

        System.out.printf("%.9f\n", left);
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글