Skip to content

Commit

Permalink
2024-12-21/회의실 배정
Browse files Browse the repository at this point in the history
  • Loading branch information
kokeunho committed Dec 23, 2024
1 parent 70811eb commit 2f69915
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
| 8차시 | 2024.11.17 | 구현 | [인구 이동](https://www.acmicpc.net/problem/16234) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/28) |
| 9차시 | 2024.11.26 | 다이나믹 프로그래밍 | [계단 오르기](https://www.acmicpc.net/problem/2579) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/33) |
| 10차시 | 2024.11.30 | 자료구조 | [가운데를 말해요](https://www.acmicpc.net/problem/1655) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/36) |
| 11차시 | 2024.12.21 | 그리디 알고리즘 | [회의실 배정](https://www.acmicpc.net/problem/1931) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/43) |
---
34 changes: 34 additions & 0 deletions kokeunho/그리디 알고리즘/11-kokeunho.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.example;

import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] meetings = new int[n][2];

for (int i = 0; i < n; i++) {
meetings[i][0] = sc.nextInt();
meetings[i][1] = sc.nextInt();
}

Arrays.sort(meetings, (a, b) -> {
if (a[1] == b[1]) {
return Integer.compare(a[0], b[0]);
}
return Integer.compare(a[1], b[1]);
});

int count = 0;
int lastEnd = 0;

for (int i = 0; i < n; i++) {
if (meetings[i][0] >= lastEnd) {
count++;
lastEnd = meetings[i][1];
}
}
System.out.println(count);
}
}

0 comments on commit 2f69915

Please sign in to comment.