반응형
Notice
Recent Posts
Recent Comments
Link
지구정복
[Greedy] 백준 - 강의실배정 본문
728x90
반응형
-자바
package greedy;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
class Lecture {
int start;
int end;
Lecture(int start, int end) {
this.start = start;
this.end = end;
}
}
public class classroom_1 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(System.out));
StringTokenizer st;
int N = Integer.parseInt( br.readLine() );
Lecture[] lectures = new Lecture[N];
for( int i=0; i<N; i++ ) {
st = new StringTokenizer(br.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
lectures[i] = new Lecture(start, end);
}
Arrays.sort(lectures, (l1, l2) -> l1.start == l2.start ? l1.end - l2.end : l1.start - l2.start);
PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.offer( lectures[0].end );
for( int i=1; i<N; i++ ) {
if( pq.peek() <= lectures[i].start ) {
pq.poll();
}
pq.offer(lectures[i].end);
}
bw.write( pq.size() + "\n" );
bw.flush();
bw.close();
br.close();
}
}
728x90
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[Greedy] 백준 - DNA (0) | 2021.06.05 |
---|---|
[Greedy] 백준 - 모두의마블 (0) | 2021.06.04 |
[Greedy] 백준 - 신입사원 (0) | 2021.06.03 |
[Greedy] 백준 - 동전0 (0) | 2021.06.03 |
[완전탐색] 프로그래머스 - 모의고사 (0) | 2021.04.11 |
Comments