728x90
https://www.acmicpc.net/problem/1931
1931번: 회의실 배정
(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.
www.acmicpc.net
풀이)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class Main_BJ_1931_회의실배정 {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[][] arr = new int[n][2];
StringTokenizer st;
for(int i=0; i<n; i++){
st = new StringTokenizer(br.readLine());
arr[i][0] = Integer.parseInt(st.nextToken());
arr[i][1] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if(o1[1] == o2[1])
return o1[0]-o2[0];
else
return o1[1]-o2[1];
}
});
int cnt = 0;
int end = 0;
for (int i = 0; i < n; i++) {
if(arr[i][0] >= end){
end = arr[i][1];
cnt++;
}
}
System.out.println(cnt);
}//main
}
종료 시간을 기준으로 정렬을 했어야 했는데,,, 시작시간을 기준으로 삼아버려서 살짝 헤맸다.
2차원 배열일 때 정렬하는 방법 다시 기억하자!
728x90
'코테 > 백준' 카테고리의 다른 글
백준 1927 최소 힙(JAVA) (1) | 2023.01.17 |
---|---|
백준 1620 나는야 포켓몬 마스터 이다솜(JAVA) (1) | 2023.01.17 |
백준 1003 피보나치 함수(JAVA) (0) | 2023.01.15 |
백준 11726 2xn 타일링(JAVA) (0) | 2023.01.14 |
백준 1107 리모컨(JAVA) (1) | 2023.01.14 |