Skip to content

Commit 5d22e0f

Browse files
committed
Java Algorithm
1 parent 60d64a7 commit 5d22e0f

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

BOJ_JAVA/src/BOJ/BOJ_1946.java

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package BOJ;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.*;
7+
8+
public class BOJ_1946 {
9+
public static void main(String[] args) throws IOException {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
int T = Integer.parseInt(br.readLine());
12+
13+
for (int tc = 1; tc <= T; tc++) {
14+
int N = Integer.parseInt(br.readLine());
15+
ArrayList<Node> arr = new ArrayList<>();
16+
for (int i = 0; i< N; i++) {
17+
StringTokenizer st= new StringTokenizer(br.readLine());
18+
int s1 = Integer.parseInt(st.nextToken());
19+
int s2 = Integer.parseInt(st.nextToken());
20+
arr.add(new Node(s1, s2));
21+
}
22+
23+
Collections.sort(arr, (s1, s2) -> s1.s1 - s2.s1);
24+
25+
int tmp = arr.get(0).s2;
26+
int ans = 0;
27+
28+
for (int i = 0; i < arr.size(); i++) {
29+
if (arr.get(i).s2 > tmp) {
30+
ans++;
31+
} else {
32+
tmp = arr.get(i).s2;
33+
}
34+
35+
}
36+
System.out.println(N - ans);
37+
}
38+
br.close();
39+
}
40+
41+
static class Node{
42+
int s1, s2;
43+
public Node(int s1, int s2) {
44+
this.s1 = s1;
45+
this.s2 = s2;
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)