백준 Basalt Breakdown

KIMYEONGJUN·2026년 4월 21일
post-thumbnail

문제

내가 생각했을때 문제에서 원하는부분

The input consists of:
One line with an integer a (1 ≤ a ≤ 10^18), the area of the hexagonal rock face in square centimetres.

Output the perimeter of the rock face in centimetres.
Your answer should have an absolute or relative error of at most 10^-6.

내가 이 문제를 보고 생각해본 부분

a는 기하학적 면적인 정수형 입력이다.
변 길이 s는 넓이 공식을 s에 대해서 변형하여 Math.sqrt 함수로 계산한다.
Math.sqrt(3)는 3의 제곱근 값을 반환한다.
둘레는 변 길이 s에 6을 곱해 구한다.
소수점 8자리(%.8f)까지만 출력한다.

코드로 구현

package baekjoon.baekjoon_34;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

// 백준 21983번 문제
public class Main1367 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // 입력: 넓이 a
        long a = Long.parseLong(br.readLine());

        // 1. 정규 육각형 변 길이 s 계산
        double s = Math.sqrt((2.0 * a) / (3.0 * Math.sqrt(3)));

        // 2. 둘레 계산: 6 * s
        double perimeter = 6.0 * s;

        // 3. 결과 출력 (소수점 8자리 정도 까지 출력 가능)
        System.out.printf("%.8f\n", perimeter);
        br.close();
    }
}

마무리

코드와 설명이 부족할수 있습니다. 코드를 보시고 문제가 있거나 코드 개선이 필요한 부분이 있다면 댓글로 말해주시면 감사한 마음으로 참고해 코드를 수정 하겠습니다.

profile
Junior backend developer

0개의 댓글