-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10000원영역.py
More file actions
87 lines (76 loc) · 2.3 KB
/
10000원영역.py
File metadata and controls
87 lines (76 loc) · 2.3 KB
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
import sys
input = sys.stdin.readline
from bisect import bisect_left
sys.setrecursionlimit(10**6)
def checking(next_circle, my_right):
# 다음원의 오른쪽과 내 오른쪽이 겹치면?
if circles[next_circle][1] == my_right:
return 1
# 안겹치면 ? 나랑 그 다음 겹치는 놈을 찾으러 들어감.
elif circles[next_circle][1] != my_right:
tmp =bisect_left(circles,[circles[next_circle][1],])
if circles[tmp][0] is not None and circles[tmp][0] == circles[next_circle][1]:
return 1* checking(tmp,my_right)
else:
return 0
else:
return 0
n = int(input())
circles= []
for _ in range(n):
center , radius= map(int,input().split())
circles.append([center-radius , center + radius])
circles.sort( key= lambda x:( x[0], -x[1]))
ans = 2
for i in range(n-1):
if circles[i][0] == circles[i+1][0]:
# 완전히 겹칠때
if circles[i][1] == circles[i+1][1]:
ans+=1
# 안쪽으로 겹칠때
else:
next_circle = bisect_left(circles,[circles[i+1][1],])
# 오른쪽도 접하는 원이 있다면?
try:
if circles[next_circle][0] == circles[i+1][1]:
# 나랑 그 다음원까지 원
if checking(next_circle, circles[i][1]):
ans +=2
# 나만 원
else:
ans +=1
# 왼쪽만 접하는 원.
else:
ans+=1
except:
ans += 1
# 왼쪽 겹침.
else:
ans +=1
print(ans)
# 다른풀이/.
import sys
from bisect import bisect_left
input = sys.stdin.readline
sys.setrecursionlimit(400000)
def next_circle(cur_c,next_c):
global cnt
if circles[cur_c][1] == circles[next_c][1]:
cnt += 1
return
tmp = bisect_left(circles,(circles[next_c][1],))
if tmp == len(circles):
return
if circles[tmp][0]==circles[next_c][1]:
next_circle(cur_c,tmp)
n = int(input())
circles = []
for i in range(n):
x,r = map(int,input().split())
circles.append((x-r,x+r))
circles.sort(key=lambda x:(x[0],-x[1]))
cnt = 0
for i in range(n-1):
if circles[i][0] == circles[i+1][0]:
next_circle(i,i+1)
print(n+cnt+1)