Pagini recente » Cod sursa (job #657833) | Cod sursa (job #1337113) | Cod sursa (job #2177320) | Cod sursa (job #974216) | Cod sursa (job #1758343)
#include <bits/stdc++.h>
using namespace std;
typedef double f64;
const int NMAX = 50005;
struct PTX {
f64 x, y;
inline PTX() { }
inline PTX(f64 _x, f64 _y) {
x = _x;
y = _y;
}
friend ifstream& operator >> (ifstream &fs, PTX &arg) {
fs>>arg.x>>arg.y;
}
friend ofstream& operator << (ofstream &fs, PTX &arg) {
fs<<setprecision(5)<<arg.x<<' '<<arg.y;
}
};
int n;
PTX pts[NMAX];
inline f64 dist(const PTX &a, const PTX &b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
inline f64 sdist(const PTX &arg) {
f64 sum = 0.;
for(int i=0; i<n; ++i)
sum+= dist(arg, pts[i]);
return sum;
}
int sx[] = {1, 0, 0, -1},
sy[] = {0, 1, -1, 0};
int main(void) {
ifstream fi("adapost2.in");
ofstream fo("adapost2.out");
PTX tmp, ant(0., 0.);
f64 cdt, tdt;
fi>>n;
for(int i=0; i<n; ++i)
fi>>pts[i].x>>pts[i].y;
cdt = sdist(ant);
for(f64 p=1000.; p>1e-8; p/=2.) {
for(int i=0; i<4; ++i) {
tmp.x = ant.x + p * sx[i];
tmp.y = ant.y + p * sy[i];
tdt = sdist(tmp);
if(tdt < cdt) {
cdt = tdt;
ant = tmp;
}
}
}
fo<<setprecision(5)<<ant.x<<' '<<ant.y<<'\n';
// fo<<ant<<'\n';
fi.close();
fo.close();
return 0;
}