Written by
java-style
on
on
백준/1085/직사각형에서 탈출/JAVA
백준/1085/직사각형에서 탈출/JAVA
1085번: 직사각형에서 탈출 (acmicpc.net)
문제
한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램을 작성하시오.
입력
첫째 줄에 x, y, w, h가 주어진다.
출력
첫째 줄에 문제의 정답을 출력한다.
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int x = in.nextInt(); int y = in.nextInt(); int w = in.nextInt(); int h = in.nextInt(); int x_min = Math.min(x, w-x); int y_min = Math.min(y, h-y); System.out.println(Math.min(x_min, y_min)); } }
Math.min 함수를 이용하여 문제를 접근하였다.
from http://minsolit.tistory.com/32 by ccl(A) rewrite - 2021-10-26 11:02:16