【py.checkio】Count Chains
题目:Count Chains - python coding challenges - Py.CheckiO
代码:
from typing import List, Tuple
import numpy as np
import math
def count_chains(circles: List[Tuple[int, int, int]]) -> int:
circles.sort(key=lambda x: x[0])
# 计算圆心距离,判断两圆是否相交,相交True,不相交返回False
# 两个圆半径绝对值 < 两圆心距离 < 两个圆半径和,则两个圆相交
def get_distances(c1, c2):
p1 = np.array(c1[:2])
p2 = np.array(c2[:2])
p3 = p2 - p1
p4 = math.hypot(p3[0], p3[1]) # 圆心距离
R0 = abs(
共有 0 条评论