Computer Science (CS)/알고리즘
[백준/Java] 직사각형에서 탈출
eune7
2023. 5. 22. 16:46
728x90
반응형
문제
정답 풀이
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 = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int w = Integer.parseInt(st.nextToken());
int h = Integer.parseInt(st.nextToken());
int min_x = Math.min(x, w-x);
int min_y = Math.min(y, h-y);
System.out.print(Math.min(min_x, min_y));
br.close();
}
}
- 메모리 14288KB
- 시간 124ms
현재 위치한 좌표에서 (0, 0)과 (w, h)와의 거리를 각각 구해서 제일 작은 거리를 출력하면 됩니다.
728x90
반응형