728x90

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
 
public class BeakJoon_1931 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int N = Integer.parseInt(br.readLine());
 
        int [][] room = new int[N][2];
 
        for(int i = 0; i<N; i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            room[i][0= Integer.parseInt(st.nextToken());
            room[i][1= Integer.parseInt(st.nextToken());
        }
        
        /**
        * 회의가 끝나는 시점으로 정렬 
        */
        Arrays.sort(room, new Comparator<int[]>() {
           
             @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[1== o2[1]){
                    return o1[0- o2[0];
                }
                return o1[1]- o2[1];
            }
        });
 
        int cnt = 0;
        int end_time = 0;
 
        for(int i = 0; i < N; i++){
            if(end_time <= room[i][0]){ //endtime 값이 회의 시작 시간보다 작다면 
                end_time = room[i][1]; //그 회의에 끝나는 시간을 endtime로 정의
                cnt++
            }
        }
 
        System.out.println(cnt);
    }
}
 
cs
728x90

'Dev > 알고리즘 ,자료구조' 카테고리의 다른 글

[Algorithm]BeakJoon_1541  (0) 2021.07.18
[Algorithm]BeakJoon_11399  (0) 2021.07.18
[Algorithm]BeakJoon_14681  (0) 2021.07.18
[Algorithm]BeakJoon_1330  (0) 2021.07.18
Insertion_Sort(삽입 정렬)  (0) 2021.06.30