Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

전공공부

[BOJ_2075] N번째로 큰 수 본문

Study/Problem Solving

[BOJ_2075] N번째로 큰 수

monitor 2023. 11. 5. 14:17

설명


N번째로 들어오는 큰 수를 구하면되므로 사실 상 크게 고려할 필요 없이 최소힙을 사용해서 N*N 크기의 값을 받아오면서 N 사이즈 이상일때 빼고 그것을 마지막까지 반복하면 마지막에 남은 값이 N번째로 큰 수가 된다.

 

 

코드


package Data_Structure;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class BOJ_2075 {
    public static void main(String[] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tk = new StringTokenizer(in.readLine(), " ");

        int N = Integer.parseInt(tk.nextToken());
        PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });
        for(int i = 0; i < N; i++){
            tk = new StringTokenizer(in.readLine(), " ");
            for(int j = 0; j < N; j++){
                pq.add(Integer.parseInt(tk.nextToken()));
                if(pq.size() > N){
                    pq.poll();
                }
            }
        }
        System.out.println(pq.poll());
    }
}
 

2075번: N번째 큰 수

첫째 줄에 N(1 ≤ N ≤ 1,500)이 주어진다. 다음 N개의 줄에는 각 줄마다 N개의 수가 주어진다. 표에 적힌 수는 -10억보다 크거나 같고, 10억보다 작거나 같은 정수이다.

www.acmicpc.net

 

'Study > Problem Solving' 카테고리의 다른 글

[BOJ_11728] 배열 합치기  (0) 2023.11.07
[BOJ_7662] 이중 우선순위 큐  (2) 2023.11.07
[BOJ_22942] 데이터 체커  (1) 2023.11.04
[BOJ_19532] 수학은 비대면강의입니다.  (1) 2023.11.03
[BOJ_2231] 분해 합  (1) 2023.11.02