Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
87735 sh25_shenpy 邮局选址问题 Python3 通过 28 MS 3696 KB 604 2026-04-24 16:34:51

Tests(1/1):


n = int(input()) points = [] for _ in range(n): x, y = map(int, input().split()) points.append((x, y)) # 分离x和y坐标 x_coords = [p[0] for p in points] y_coords = [p[1] for p in points] # 对坐标进行排序 x_coords.sort() y_coords.sort() # 找到中位数 # 对于奇数和偶数n,n//2 都能给出正确的中位数索引 median_x = x_coords[n // 2] median_y = y_coords[n // 2] # 计算所有点到中位数点的曼哈顿距离总和 total_distance = 0 for x, y in points: total_distance += abs(x - median_x) + abs(y - median_y) print(total_distance)


测评信息: