Pagini recente » Cod sursa (job #796841) | Cod sursa (job #958353) | Cod sursa (job #1231696) | Cod sursa (job #2741944) | Cod sursa (job #2066446)
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define mod 1000000007LL
using namespace std;
typedef long long ll;
typedef pair< int , int > PII;
int n, m;
ll px, py;
double x, y;
PII a[50005];
ll dist(int x, int y, int xx, int yy){
return (ll)sqrt(1LL * (xx - x) * (xx - x) + 1LL * (yy - y) * (yy - y));
}
ll check(int x, int y){
int rs = 0;
for (int i = 1; i <= n; i++)
rs += dist(x, y, a[i].x, a[i].y);
return rs;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ifstream cin("adapost2.in");
ofstream cout("adapost2.out");
cin >> n;
for (int i = 1; i <= n; i++){
cin >> x >> y;
a[i] = {x * 1000, y * 1000};
px += a[i].x;
py += a[i].y;
}
px /= n; py /= n; //stabilesc o pozitie de start optima
ll CURR = check(px, py);
int pas = 5000;
while (pas >= 1){
ll R = check(px + pas, py);
ll L = check(px - pas, py);
ll U = check(px, py + pas);
ll D = check(px, py - pas);
if (min({R, L, U, D}) >= CURR){pas /= 2; continue;}
ll mn = min({R, L, U, D});
px += (R == mn ? pas : (L == mn ? -pas : 0));
py += (U == mn ? pas : (D == mn ? -pas : 0));
CURR = mn;
}
cout << setprecision(4) << fixed << px / 1.0 << " " << py / 1.0;
}