提交时间:2026-04-24 16:34:51

运行 ID: 87735

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)