티스토리 뷰

https://www.acmicpc.net/problem/1931

 

코드

import java.io.*;
import java.util.*;

public class Main {

    static int N;
    static List<Meeting> meetings = new ArrayList<>();

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        N = Integer.parseInt(br.readLine());

        StringTokenizer st;
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            meetings.add(new Meeting(a, b));
        }

        Collections.sort(meetings);

        int cnt = 0;
        int startTime = 0;
        for (Meeting meeting : meetings) {
            if (startTime <= meeting.start) {
                cnt++;
                startTime = meeting.end;
            }
        }

        System.out.println(cnt);
    }

    static class Meeting implements Comparable<Meeting> {

        int start, end;

        public Meeting(int start, int end) {
            this.start = start;
            this.end = end;
        }

        @Override
        public int compareTo(Meeting other) {
            if (this.end == other.end) {
                return this.start - other.start;
            }
            return this.end - other.end;
        }
    }
}
Total
Today
Yesterday
최근에 올라온 글
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30