Created
September 18, 2018 14:03
-
-
Save developer-sdk/d2567c5135afaf89e7e2adc5d3128edc to your computer and use it in GitHub Desktop.
백준,1931,회의실배정
This file contains hidden or 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.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStreamReader; | |
| import java.util.Arrays; | |
| import java.util.Comparator; | |
| public class Problem1931 { | |
| static int size; | |
| public static void main(String[] args) throws NumberFormatException, IOException { | |
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
| size = Integer.parseInt(br.readLine()); | |
| int[][] meetings = new int[size][2]; | |
| // 데이터 입력 | |
| for(int i = 0; i < size; i++) { | |
| String[] datas = br.readLine().split(" "); | |
| meetings[i][0] = Integer.parseInt(datas[0]); | |
| meetings[i][1] = Integer.parseInt(datas[1]); | |
| } | |
| // 종료 시간으로 정렬 | |
| Arrays.sort(meetings, new Comparator<int[]>() { | |
| @Override | |
| public int compare(int[] a, int[] b) { | |
| if(a[1] < b[1]) { | |
| return -1; | |
| } else if(a[1] == b[1]) { | |
| return a[0] <= b[0] ? -1 : 1; | |
| } | |
| return 1; | |
| } | |
| }); | |
| int count = 1; | |
| int[] prev = meetings[0]; | |
| for(int i = 1; i < size; i++) { | |
| if(prev[1] <= meetings[i][0]) { | |
| count++; | |
| prev = meetings[i]; | |
| } | |
| } | |
| System.out.println(count); | |
| } | |
| } |
This file contains hidden or 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 sys | |
| read = sys.stdin.readline | |
| N = int(read()) | |
| meetings = [] | |
| i = 0 | |
| while i < N: | |
| datas = read().split() | |
| meetings.append((int(datas[0]), int(datas[1]))) | |
| i += 1 | |
| meetings = sorted(meetings, key=(lambda x: (x[1], x[0]))) | |
| prev_meeting = meetings[0] | |
| count = 1 | |
| for idx, meeting in enumerate(meetings): | |
| if idx == 0: | |
| continue | |
| if prev_meeting[1] <= meeting[0]: | |
| prev_meeting = meeting | |
| count += 1 | |
| print(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment