View

λ°˜μ‘ν˜•

문제

**N개의 ν™”ν•™ 물질 C1, C2, …, Cn이 μžˆλ‹€.
이듀 각각은 λ³΄κ΄€λ˜μ–΄μ•Ό ν•  μ˜¨λ„κ°€ 각기 λ‹€λ₯Έλ°, 각 Ciλ§ˆλ‹€ μ΅œμ € 보관 μ˜¨λ„ xi와 졜고 보관 μ˜¨λ„ yiκ°€ μ •ν•΄μ Έ μžˆλ‹€.
즉 CiλŠ” μ˜¨λ„ xi이상, yiμ΄ν•˜μ˜ μ˜¨λ„μ—μ„œ λ³΄κ΄€λ˜μ–΄μ•Όλ§Œ μ•ˆμ „ν•˜λ‹€.

이 ν™”ν•™ λ¬Όμ§ˆλ“€μ„ λͺ¨λ‘ λ³΄κ΄€ν•˜κΈ° μœ„ν•΄μ„œλŠ” μ—¬λŸ¬ λŒ€μ˜ 냉μž₯κ³ κ°€ ν•„μš”ν•œλ° κ°€λŠ₯ν•˜λ©΄ 적은 수의 냉μž₯κ³ λ₯Ό μ‚¬μš©ν•˜κ³  μ‹Άλ‹€.
이λ₯Ό ν•΄κ²°ν•˜λŠ” ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•˜μ‹œμ˜€.**

μž…λ ₯ν˜•μ‹

첫쀄에 ν™”ν•™λ¬Όμ§ˆμ˜ 수 N이 μž…λ ₯λœλ‹€. N의 λ²”μœ„λŠ” 1이상 100 μ΄ν•˜μ΄λ‹€.
두 번째 쀄뢀터 N+1μ€„κΉŒμ§€ μ΅œμ €λ³΄κ΄€μ˜¨λ„μ™€ μ΅œκ³ λ³΄κ΄€μ˜¨λ„κ°€ μž…λ ₯λœλ‹€.
λ³΄κ΄€μ˜¨λ„λŠ” -270° ~ 10000°μ΄λ©°, 각 냉μž₯κ³ λŠ” μž„μ˜μ˜ 정해진 μ˜¨λ„λ₯Ό μΌμ •ν•˜κ²Œ μœ μ§€ν•  수 있고, 냉μž₯κ³ λŠ” μ•„μ£Ό 크닀고 κ°€μ •ν•œλ‹€.

좜λ ₯ν˜•μ‹

첫쀄에 μ΅œμ†Œλ‘œ ν•„μš”ν•œ 냉μž₯고의 λŒ€μˆ˜λ₯Ό 좜λ ₯ν•œλ‹€.

μž…λ ₯ 예

4
-15 5
-10 36
10 73
27 44

좜λ ₯ 예

2


문제 이해가 잘 λ˜μ§€ μ•Šμ•„μ„œ 쑰금 μ‹œκ°„μ΄ κ±Έλ Έλ‹€


🀦‍♀️ My Solution

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main_1828 {

    static class Node {
        int s;
        int e;

        public Node(int s, int e) {
            super();
            this.s = s;
            this.e = e;
        }

    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        ArrayList<Node> mInfo = new ArrayList<>();

        int N = Integer.parseInt(br.readLine());

        for (int i = 0; i < N; i++) {
            // μ΅œλŒ“κ°’(끝값)이 κ°€μž₯ μž‘μ€ μ•  -> 1개
            st = new StringTokenizer(br.readLine());
            int s = Integer.parseInt(st.nextToken());
            int e = Integer.parseInt(st.nextToken());
            mInfo.add(new Node(s, e));
        }

        int res = 0;
        while (!mInfo.isEmpty()) {
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < mInfo.size(); i++) {
                if (min > mInfo.get(i).e) {
                    min = mInfo.get(i).e;
                }

            }

            for (int i = 0; i < mInfo.size(); i++) {
                if (min >= mInfo.get(i).s) {
//min 보닀 μž‘μ€ κ°’ μ‹œμž‘κ°’ 듀은 λͺ¨λ‘ μ‚­μ œ 
                    mInfo.remove(i);
                    i--;
                } else {
                    continue;
                }
            }
            res += 1;

        }
        System.out.println(res);
    }

}

λ°˜μ‘ν˜•
Share Link
reply
λ°˜μ‘ν˜•
Β«   2025/02   Β»
일 μ›” ν™” 수 λͺ© 금 ν† 
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