백준 문제풀이

백준 20306 - 블랙홀

Vermeil 2022. 11. 12. 02:53

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

 

20306번: 블랙홀

첫째 줄에 정수 $N$, $M$, $K$가 주어진다. ($3 \le N \le 100\ 000$, $1 \le K \le M \le 100\ 000$) 둘째 줄에 블랙홀의 특이점의 좌표가 주어진다. 셋째 줄부터 $N$개 줄에 걸쳐 블랙홀의 꼭짓점들의 좌표가 반시

www.acmicpc.net

[알고리즘 분류]

이분 탐색 + 스위핑

 

 

 일단 정해는 점과 직선의 거리를 이용하여 각 점이 블랙홀에 먹히는 시간을 구하는 것이다.

 나는 귀찮아서 그냥 파이썬을 이용해 이분 탐색으로 시간을 구했다.

 

 먼저 360도 정렬을 한다.

 블랙홀이 커질 때, 각 집이 어떤 선분에 제일 먼저 닿는지 구할 수 있다.

 이 선분이 언제 집을 집어삼키는지를 이분 탐색으로 찾으면 된다.

 

 정렬을 할 때, cmp_to_key를 사용하면 된다.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
import sys
input = sys.stdin.readline
 
 
# input
def ip(): return int(input())
def sp(): return str(input().rstrip())
 
 
def mip(): return map(int, input().split())
def mfp(): return map(float, input().split())
def msp(): return map(str, input().split())
 
 
def lmip(): return list(map(int, input().split()))
def lmsp(): return list(map(str, input().split()))
 
############ Main! #############
 
 
from functools import cmp_to_key
 
 
def cmp(x, y):
    if (x[0][0<= 0!= (y[0][0< 0):
        if x[0][0> y[0][0]:
            return 1
        else:
            return -1
    else:
        if x[0][1* y[0][0< x[0][0* y[0][1]:
            return -1
        return 1
 
def ccw(a,b,c):
    return a[0]*b[1]+b[0]*c[1]+c[0]*a[1- a[1]*b[0]-b[1]*c[0]-c[1]*a[0>= 0
 
 
def get(i,la,lb,ra,rb):
    lo = 0
    hi = 10 ** 19
 
    while lo <= hi:
        mid = (lo + hi) // 2
        l = [la, lb]
        r = [ra, rb]
        l[0*= mid + 1
        l[1*= mid + 1
        r[0*= mid + 1
        r[1*= mid + 1
        if ccw(l,r,v[i][0]):
            hi = mid - 1
        else:
            lo = mid + 1
    return lo
 
 
= []
bl = []
cnt = []
n,m,k=mip()
px,py=mip()
for i in range(n):
    x,y=mip()
    v.append([[x-px,y-py],1])
    bl.append([[x-px,y-py],1])
for i in range(m):
    x,y=mip()
    v.append([[x-px,y-py],0])
 
v.sort(key=cmp_to_key(cmp))
bl.sort(key=cmp_to_key(cmp))
 
= n - 1
for i in range(n+m):
    if v[i][1]:
        L = (L + 1) % n
        continue
    cnt.append(get(i, bl[L][0][0], bl[L][0][1], bl[(L+1)%n][0][0], bl[(L+1)%n][0][1]))
 
cnt.sort()
 
print(cnt[k-1])
cs

 

'백준 문제풀이' 카테고리의 다른 글

백준 23750 - Leader-based Team Distribution  (2) 2022.12.12
2022 ICPC Seoul Regional Problem C. Empty Quadrilaterals  (5) 2022.11.21
백준 18619 - Alakazam  (0) 2022.10.29
백준 18032 - Dazzling Stars  (0) 2022.10.17
9/26 ~ 10/9 PS  (0) 2022.10.10