코린이의 소소한 공부노트

[백준 온라인 저지] 9063. 대지 본문

코딩테스트 풀이/JAVA

[백준 온라인 저지] 9063. 대지

무지맘 2023. 3. 29. 21:22

- 입력: 첫째 줄에는 점의 개수 N (1 N 100,000) 이 주어진다. 이어지는 N 줄에는 각 점의 좌표가 두 개의 정수로 한 줄에 하나씩 주어진다. 각각의 좌표는 -10,000 이상 10,000 이하의 정수이다.

 

- 출력: 첫째 줄에 N 개의 점을 둘러싸는 최소 크기의 직사각형의 넓이를 출력하시오.

 

import java.io.*;
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.valueOf(br.readLine()), answer = 0, xmin, xmax, ymin, ymax;
        if(n>1){
            String[] input = br.readLine().split(" ");
            int a = Integer.valueOf(input[0]), b = Integer.valueOf(input[1]);
            input = br.readLine().split(" ");
            int c = Integer.valueOf(input[0]), d = Integer.valueOf(input[1]);
            xmin = Math.min(a,c); xmax = Math.max(a,c);
            ymin = Math.min(b,d); ymax = Math.max(b,d);
            for(int i=2 ; i<n ; i++){
                input = br.readLine().split(" ");
                a = Integer.valueOf(input[0]); b = Integer.valueOf(input[1]);
                xmin = Math.min(a,xmin); xmax = Math.max(a,xmax);
                ymin = Math.min(b,ymin); ymax = Math.max(b,ymax);
            }
            answer = (ymax-ymin)*(xmax-xmin);
        }
        System.out.print(answer);       
    }
}