https://www.acmicpc.net/problem/1085
1085번: 직사각형에서 탈출
한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램
www.acmicpc.net
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int x,y,w,h;
x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
w = Integer.parseInt(st.nextToken());
h = Integer.parseInt(st.nextToken());
int width = Math.min(x, w-x);
int height = Math.min(y, h-y);
int shortCut = Math.min(width, height);
System.out.println(shortCut);
}
}
'알고리즘 > 백준' 카테고리의 다른 글
백준 3009번 - 네 번째 점 (Java 8) (0) | 2022.02.25 |
---|---|
백준 3053번 - 택시 기하학 (Java 8) (0) | 2022.02.25 |
백준 1929번 - 소수 구하기 (Java 8) (0) | 2022.02.24 |
백준 4948번 - 베르트랑 공준 (Java 8) (0) | 2022.02.24 |
백준 9020번 - 골드바흐의 추측 (Java 8) (0) | 2022.02.24 |
댓글