Sun, 24 Feb 2019 12:10:11 +0800
parent
2c02e984a7
commit
63ad7a1231
@ -1,8 +1,56 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue