"꾸준하고 완벽한 한 걸음"

PS/Baekjoon Online Judge

[백준 12571] Rope Intranet (Small) [Java]

kimyoungrok 2025. 3. 2. 18:07
728x90

문제

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

 


풀이

선분의 양쪽 끝 위치 정보가 주어졌을 때, 선분들의 교차점을 모두 세는 문제다.

N은 2이하로, 단순 비교를 통해 선분의 시작점에 대해 교착점을 탐색하면 된다.

            // Solve
            if (N == 1) {
                sb.append(String.format("Case #%d: 0\\n", t));
            } else {
                final int A1 = input[0];
                final int B1 = input[1];
                input = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
                final int A2 = input[0];
                final int B2 = input[1];
                final int res = (A1 < A2 && B1 > B2 ? 1:0) + (A1 > A2 && B1 < B2 ? 1:0);
                sb.append(String.format("Case #%d: %d\\n", t, res));
            }

소스코드

https://github.com/rogi-rogi/problem-solving/blob/main/baekjoon-online-judge/practice/12571.java

728x90