侧边栏壁纸
  • 累计撰写 192 篇文章
  • 累计创建 2 个标签
  • 累计收到 87 条评论

【题解】【上海】【城市中心】

Allen Best
2023-08-08 / 0 评论 / 0 点赞 / 31 阅读 / 443 字
温馨提示:
本文最后更新于 2023-08-08,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
#include <iostream>
#include <algorithm>
using namespace std;

int n, ans = 0;
struct dis {
	int x, y;
} s[100000];
bool xcmp(dis a, dis b) {
	return a.x < b.x;
}
bool ycmp(dis a, dis b) {
	return a.y < b.y;
}

int main() {
	cin.tie(0);
	cin >> n;

	for (int i = 0; i < n ; ++i)
		cin >> s[i].x >> s[i].y;

	sort(s, s + n, xcmp);
	int advx = s[n / 2].x;
	sort(s, s + n, ycmp);
	int advy = s[n / 2].y;

	for (int i = 0; i < n ; ++i) {
		ans += abs(s[i].x - advx);
		ans += abs(s[i].y - advy);
	}

	cout << ans << endl;
	return 0;
}

0

评论区