Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/2162
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
2차원 평면에 선분$N$ 개가 있다.
두 선분이 서로 교차하거나 한 끝 점을 공유할 때, 같은 그룹에 속한다고 한다.
그룹의 수와, 가장 큰 그룹에 있는 선분 개수를 구해보자.
🔍 풀이 방법
2중 반복문으로 각 선분이 교차하는지 확인해서 교차한다면 분리 집합으로 이어주면 된다.
선분이 교차하는지 여부는 CCW와 (매우) 많은 조건 분기를 통해 알아냈다.
선분 A와 B가 교차하는지 여부를 구하기 위해, 네 가지 CCW를 판별한다.
우선, 1,2,3,4가 모두 0이 아니라 가정하자.
만약 1,2의 부호가 0이 아니고 서로 다르다면, A를 연장시킨 직선이 B를 이루는 두 점을 나누게 된다는 의미이다.
-> 교차할 가능성이 있다.
마찬가지로, 3,4의 부호가 0이 아니고 서로 다르다면, B를 연장시킨 직선이 A를 이루는 두 점을 나누게 된다.
-> 교차할 가능성이 있다.
두 조건을 모두 만족한다면, 항상 교차한다.
그렇지 않으면, 위의 논리대로면 교차하지 않는다는 걸 알 수 있다.
1,2,3,4 중 0이 있다고 가정하면, 해당 CCW를 구할 때 사용된 세 점이 한 직선위에 있음을 의미한다.
좌표값 비교를 통해, 선분 내에 다른 점이 포함되는지 확인해주면 된다.
⏳ 회고
조건 분기가 너무 힘들었다. 반례 게시판 보려다가 꾹 참고 결국 해냈다...