오늘 푼 문제
import java.io.*;
import java.util.*;
public class 도미노무너트리기_25972 {
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 n = Integer.parseInt(br.readLine());
Domino[] domino = new Domino[n];
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int l = Integer.parseInt(st.nextToken());
domino[i] = new Domino(a, l);
}
Arrays.sort(domino, new Comparator<Domino>() {
@Override
public int compare(Domino d1, Domino d2) {
return Integer.compare(d1.a, d2.a);
}
});
int cnt = 1;
for (int i = 0; i < n - 1; i++) {
if ((domino[i].a + domino[i].l) < domino[i + 1].a) {
cnt++;
}
}
bw.write(cnt + "");
bw.flush();
bw.close();
}
}
class Domino {
int a;
int l;
public Domino(int a, int l) {
this.a = a;
this.l = l;
}
}
문제가 악랄한게 예제에는 다 정렬된 녀석들만 줘서 정렬의 필요성을 못 느끼지만, 실제로는 정렬이 필요한 문제다..!
그래서 저번에 써먹었던 특정 파라미터를 기준으로 정렬하는 방법을 또 써먹었다.
그리고 넘어지면 그 다음 녀석을 신경쓰는쪽이 아니라 반대로 안 넘어질때까지 한묶음으로 했더니 쉽게 풀렸다.
그리고 오늘 캡스톤도 신청하고, 정처기 실기도 신청했는데
정처기 실기는... 2시인줄 모르고 오전에 봤다가 왜 없지 하고 저녁에 다시 들가보니 이미 주변 지역 사라져서.. 진접으로 잡았다.. 전날 엄마집 가있어야지 ㅠㅠ