You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <vector>
|
|
#include <cstdio>
|
|
#include <limits>
|
|
#include <cmath>
|
|
using namespace std;
|
|
const double eps = 1e-8;
|
|
int dx[] = {1, -1, 0, 0};
|
|
int dy[] = {0, 0, 1, -1};
|
|
struct Point
|
|
{
|
|
double x, y;
|
|
} v[200];
|
|
inline double sqr(double x) { return x * x; }
|
|
inline double dis(const Point &lhs, const Point &rhs)
|
|
{
|
|
return sqrt(sqr(lhs.x - rhs.x) + sqr(lhs.y - rhs.y));
|
|
}
|
|
inline double sum(int n, const Point &p)
|
|
{
|
|
double ret = 0;
|
|
for (int i = 0; i < n; i++)
|
|
ret += dis(v[i], p);
|
|
return ret;
|
|
}
|
|
int main()
|
|
{
|
|
int n;
|
|
scanf("%d", &n);
|
|
for (int i = 0; i < n; i++)
|
|
scanf("%lf%lf", &v[i].x, &v[i].y);
|
|
Point s = v[0];
|
|
double ans = numeric_limits<double>::max() / 2;
|
|
for (int t = 100; t > eps; t *= 0.98)
|
|
{
|
|
bool flag = true;
|
|
while (flag)
|
|
{
|
|
flag = false;
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
Point p{s.x + dx[i] * t, s.y + dy[i] * t};
|
|
double cur = sum(n, p);
|
|
if (ans > cur)
|
|
{
|
|
ans = cur;
|
|
s = p;
|
|
flag = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
printf("%.0f", ans);
|
|
return 0;
|
|
} |