티스토리 뷰
이 문제는 회의실 종료시간을 오름차순으로 정렬한 후,
회의 종료시간과 다음회의의 시작시간을 비교하여 순차적으로 입력한다.
회의실이 먼저 종료되는 순으로 입력하는 것이 포인트다.
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.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.Scanner; | |
public class Problem1370 { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int n = in.nextInt(); | |
int[][] rooms = new int[n][3]; | |
for(int i = 0; i < n; i++) { | |
rooms[i][0] = in.nextInt(); | |
rooms[i][1] = in.nextInt(); | |
rooms[i][2] = in.nextInt(); | |
} | |
in.close(); | |
// int n = 6; | |
// int[][] rooms = { { 1, 1, 10 }, | |
// { 2, 5, 6 }, | |
// { 3, 13, 15 }, | |
// { 4, 14, 17 }, | |
// { 5, 8, 14 }, | |
// { 6, 3, 12 } }; | |
// 종료시간을 기준으로 오름차순으로 정렬 | |
Arrays.sort(rooms, new Comparator<int[]>() { | |
@Override | |
public int compare(int[] a, int[] b) { | |
return a[2] <= b[2] ? -1 : 1; | |
} | |
}); | |
// for(int[] room : rooms) | |
// System.out.printf("%d %2d %2d\n", room[0], room[1], room[2]); | |
ArrayList<int[]> list = new ArrayList<int[]>(); | |
list.add(rooms[0]); | |
for(int i = 1; i < rooms.length; i++) { | |
if(list.get(list.size()-1)[2] <= rooms[i][1]) { | |
list.add(rooms[i]); | |
} | |
} | |
System.out.println(list.size()); | |
for(int[] room : list) | |
System.out.printf("%d ", room[0]); | |
} | |
} |
반응형
'알고리즘 > 정올' 카테고리의 다른 글
[정올] [백트래킹] 1681 해밀턴 순환회로 (0) | 2016.07.15 |
---|---|
[정올] [백트래킹] 1889 NQueen (0) | 2016.07.14 |
[정올] [그리디] 2247 도서관 문제 (0) | 2016.07.08 |
[정올] [그리디] 1669 소시지 공장 (0) | 2016.07.07 |
[정올] 실력키우기 2255 : 섞기 수열 (0) | 2016.06.15 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- SQL
- HIVE
- 오류
- 다이나믹
- error
- Python
- nodejs
- Hadoop
- 하이브
- Tez
- SPARK
- emr
- 알고리즘
- 파이썬
- HDFS
- 백준
- Linux
- java
- S3
- 정올
- build
- mysql
- yarn
- airflow
- ubuntu
- hbase
- AWS
- 하둡
- bash
- oozie
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함