반응형
https://www.acmicpc.net/problem/1946
1946번: 신입 사원
첫째 줄에는 테스트 케이스의 개수 T(1 ≤ T ≤ 20)가 주어진다. 각 테스트 케이스의 첫째 줄에 지원자의 숫자 N(1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개 줄에는 각각의 지원자의 서류심사 성
www.acmicpc.net
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
class Edge implements Comparable<Edge>{
// boolean canUse;
int x, y;
Edge(int x, int y){
// canUse = true;
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "(" + x + "," + y + ")";
}
@Override
public int compareTo(Edge edge){
if(x!=edge.x) return (edge.x - x);
else return (edge.y - y);
}
}
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(br.readLine());
for(int T=0; T<t; T++){
int n = Integer.parseInt(br.readLine());
ArrayList<Edge> list = new ArrayList<>();
for(int i=0; i<n; i++){
String[] split = br.readLine().split(" ");
int a= Integer.parseInt(split[0]);
int b= Integer.parseInt(split[1]);
list.add(new Edge(a,b));
}
Collections.sort(list, Collections.reverseOrder());
int comp = 10000000;
int ans = 0;
for(int i=0; i<n; i++){
if(comp > list.get(i).y){
ans++;
comp = list.get(i).y;
}
}
bw.write(Integer.toString(ans));
bw.write("\n");
}
bw.flush();
}
}
반응형
'Algorithm > problem' 카테고리의 다른 글
백준 5972번 : 택배 배송 Java 다익스트라 (0) | 2022.06.11 |
---|---|
백준 1368번 : 물대기 - Java (0) | 2022.06.07 |
백준 14950번: 정복자 prim 알고리즘 - Java (0) | 2022.05.22 |
백준 2638번 : 치즈 Java (0) | 2022.05.20 |
백준 4803번 : 트리 - java DFS풀이와 Union & Find 풀이 (0) | 2022.04.30 |