Post

[BaekJoon] #16479 - 컵라면 측정하기 [Java][C++]

[BaekJoon] #16479 - 컵라면 측정하기 [Java][C++]

문제 링크


1. 아이디어

원뿔대의 윗면의 지름, 아랫면의 지름, 변의 길이가 주어졌을 때, 컵라면의 높이의 제곱을 구해야 하는 문제로 피타고라스 정리를 활용하면 해결할 수 있다.



2. 복잡도

접근시간공간
풀이$O(1)$$O(1)$

3. 코드

풀이 [Java][C++]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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));
        StringTokenizer st;

        int k = Integer.parseInt(br.readLine());

        st = new StringTokenizer(br.readLine());
        int d1 = Integer.parseInt(st.nextToken());
        int d2 = Integer.parseInt(st.nextToken());

        System.out.println(k * k - Math.pow(d1 - d2, 2) / 4);
    }
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int k, d1, d2;
    cin >> k >> d1 >> d2;
    cout << k * k - pow(d1 - d2, 2) / 4;
}

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