Last active
March 5, 2018 03:36
-
-
Save qkreltms/f663eee5861b73dc6844e0e854057ed3 to your computer and use it in GitHub Desktop.
baekjoon 1931 : 회의실 배정 https://www.acmicpc.net/problem/1931
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.Scanner; | |
class Meeting { | |
public int start; | |
public int end; | |
public Meeting(int start, int end) { | |
this.start = start; | |
this.end = end; | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int length = sc.nextInt(); | |
Meeting[] meeting = new Meeting[length]; | |
for (int i = 0; i < length; i++) { | |
meeting[i] = new Meeting(sc.nextInt(), sc.nextInt()); | |
} | |
Arrays.sort(meeting, new Comparator<Meeting> (){ //뒤가 짧아야 더 많이 배정할 수 있다고 가정. | |
@Override | |
public int compare(Meeting a, Meeting b) { | |
if (a.end == b.end) { //뒤가 같으면 | |
return Integer.compare(a.start, b.start); //앞에 것 비교 | |
} //뒤가 같지 않으면 | |
return Integer.compare(a.end, b.end); //뒤 비교 | |
} | |
}); | |
int pick = 0; | |
int ctn = 0; | |
for (int i = 0; i < length; i++) { | |
if (pick <= meeting[i].start) { | |
pick = meeting[i].end; | |
ctn++; | |
} | |
} | |
System.out.println(ctn); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment