728x90
< 처음 풀 때 >
접근 법을 아예 몰랐다. 좌표에서 좌표로 직접 가는 경우를 다 세야 하는 줄 알고 시도 조차 못했지만 해설을 보고 원 안에 포함
되어 있는 개수를 세면 된다는 것을 알게 되었다.
< 해결 방법 >
원 안에 포함이 되어 있는지 체크를 해주는 함수를 만들었고, 두 좌표 중 한 좌표만 한 원 안에 포함되어 있다면 answer+=1 을 해주었다. 두 원 모두 포함되어 있는 원도 count 해주다가 에러가 발생해서 수정을 해주었다.
import sys
import math
def check(x,y,q,w,r):
distance = math.sqrt((x-q)**2 + (y-w)**2)
if distance > r:
return False
else:
return True
test_case = sys.stdin.readline()
for i in range(0,int(test_case)):
planet = [ ]
answer = 0
x1,y1,x2,y2 = map(int,sys.stdin.readline().split(" "))
planet_count = sys.stdin.readline()
for j in range(0,int(planet_count)):
planet.append(list(map(int,sys.stdin.readline().split(" "))))
for z in range(0,len(planet)):
if check(x1,y1,planet[z][0],planet[z][1],planet[z][2]) == True and check(x2,y2,planet[z][0],planet[z][1],planet[z][2]) == False:
answer+=1
if check(x2,y2,planet[z][0],planet[z][1],planet[z][2]) == True and check(x1,y1,planet[z][0],planet[z][1],planet[z][2]) == False:
answer+=1
print(answer)
728x90
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 18870 좌표 압축 (0) | 2022.08.02 |
|---|---|
| [파이썬] 백준 2004 조합 0의 개수 (0) | 2022.08.02 |
| [파이썬] 백준 2981 검문 (0) | 2022.08.02 |
| [파이썬] 백준 15652 N과 M (4) (0) | 2022.08.01 |
| [파이썬] 백준 15651 N과 M (3) (0) | 2022.08.01 |