자바 백준 13222번
브론즈 3
https://www.acmicpc.net/problem/13222
13222번: Matches
The first line of input contains an integer N (1 ≤ N ≤ 50), the number of matches on the floor, and two integers W and H, the dimensions of the box (1 ≤ W ≤ 100, 1 ≤ H ≤ 100). Each of the following N lines contains a single integer between 1 an
www.acmicpc.net
문제 보기

분류: 수학, 기하학, 피타고라스 정리
문제 풀기
직사각형 바닥에서 가능한 최대 길이인 대각선 길이를 계산한 후 성냥이 대각선 보다 작거나 같으면 `YES`를 출력하고 그렇지 않으면 `NO`를 출력한다.
코드 보기
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int W = sc.nextInt(); int H = sc.nextInt(); double maxBottom = getMaxBottom(W, H); for (int i = 0; i < N; i++) { int match = sc.nextInt(); if (match <= maxBottom) { System.out.println("YES"); } else { System.out.println("NO"); } } } private static double getMaxBottom(int W, int H) { return Math.sqrt(Math.pow(W, 2) + Math.pow(H, 2)); } }
'공부하기 > 백준' 카테고리의 다른 글
[Java] 백준 풀기 21921 - 블로그 (0) | 2023.08.09 |
---|---|
[Java] 백준 풀기 11005 - 진법 변환 2 (0) | 2023.08.08 |
[Java] 백준 풀기 16486 - 운동장 한 바퀴 (0) | 2023.08.06 |
[Java] 백준 풀기 7510 - 고급 수학 (0) | 2023.08.05 |
[Java] 백준 풀기 9063 - 대지 (0) | 2023.08.04 |