728x90
๐๋ฌธ์ ๋งํฌ
https://www.acmicpc.net/problem/3980
๐ป์ฝ๋
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringTokenizer st;
StringBuilder sb = new StringBuilder();
for (int t = 0; t < T; t++) {
int N = Integer.parseInt(br.readLine());
int[][] applicant = new int[N][2];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
applicant[i][0] = Integer.parseInt(st.nextToken());//์๋ฅ์ ์
applicant[i][1] = Integer.parseInt(st.nextToken());//๋ฉด์ ์ ์
}
Arrays.sort(applicant, Comparator.comparingInt((int[] o) -> o[0]));
int answer = 1;// ์๋ฅ์ ์ 1๋ฑ ํต๊ณผ
int point = applicant[0][1]; //์๋ฅ์ ์ 1๋ฑ์ ๋ฉด์ ์ ์
for (int i = 1; i < N; i++) {
if(applicant[i][1]<point){
answer++;
point = applicant[i][1];
}
}
sb.append(answer).append("\n");
}
System.out.print(sb);
}
}
728x90
'Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Algorithm/Baekjoon] ์ฌ๋ฌ๋ถ์ ๋ค๋ฆฌ๊ฐ ๋์ด ๋๋ฆฌ๊ฒ ์ต๋๋ค! - 17352 (G5/JAVA) (0) | 2025.01.06 |
---|---|
[Algorithm/Baekjoon] ๋๋ฌด ํ์ถ - 15900 (S1/JAVA) (3) | 2024.12.30 |
[Algorithm/Baekjoon] ์ ๋ฐ ๋ช ๋จ - 3980(G5/JAVA) (0) | 2024.12.16 |
[Algorithm/Baekjoon] ๊ฐ๋ฏธ๊ตด - 14725(G3/JAVA) (3) | 2024.12.09 |
[Algorithm/Baekjoon] ๊ณ ๋ฅ์ด - 16472(G4/JAVA) (0) | 2024.12.05 |