코드 단축 연습이 필요합니다.
진짜 심각합니다 이거
진짜 내가 쓴 코드의 비효율성에 소름이 돋음... 숏코딩을 진지하게 연습해야할까 생각중
먼저 내 끔찍한 코드 공개:
t=int(input())
startend=[]
for _ in range(t):
centre=[]
startend = list(map(int, input().split()))
n=int(input())
cnt=0
x1=startend[0]
y1=startend[1]
x2=startend[2]
y2=startend[3]
for k in range(n):
line = []
line = list(map(int, input().split()))
centre.append(line)
r=centre[k][2]
if(centre[k][0]-r<x1<centre[k][0]+r and centre[k][1]-r<y1<centre[k][1]+r):
cnt+=1
elif(centre[k][0]-r<x2<centre[k][0]+r and centre[k][1]-r<y2<centre[k][1]+r):
cnt+=1
print(cnt)
그리고 단축시킨 코드 공개.
수학 상 원방에 나온 내용인데 아직 과외학생 진도가 여기까지 안나가서 존재를 까먹고 미처 쓸 생각을 못했다.
이건 프로그래머 지망생으로써 문제가 아니라 수학과외 선생으로써 자격이 있는지 심히 의심된다.
(까먹었던 내용을 과외학생과 같이 공부하는급ㅋㅋㅋ)
여튼 원방을 기억해내고 고치긴 했다.
t = int(input())
for i in range(t):
cnt = 0
x1, y1, x2, y2 = map(int, input().split())
n = int(input())
for i in range(n):
cx, cy, cr = map(int, input().split())
d1 = (((x1 - cx) ** 2) + ((y1 - cy) ** 2)) ** 0.5
d2 = (((x2 - cx) ** 2) + ((y2 - cy) ** 2)) ** 0.5
if (d1 < cr and d2 > cr) or (d1 > cr and d2 < cr):
cnt += 1
print(cnt)
'언어는 과-학인가요? > python 파이썬' 카테고리의 다른 글
(진짜재밌었음) 백준 골드 (1011번) 파이썬 - Fly me to the Alpha Centauri (0) | 2022.07.28 |
---|---|
백준 골드 (2448번) 파이썬 - 별찍기 (0) | 2022.07.28 |
백준 1072 파이썬 - 게임 (0) | 2022.07.27 |
백준 골드 (2447번) 파이썬 - 별찍기 (0) | 2022.07.27 |
백준 골드 (2493번) 파이썬 (0) | 2022.07.27 |