基础题。基地的X坐标为所有点X坐标的中位数,Y坐标为所有点Y坐标的中位数。
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
const int MAXN = 1000005;
double x[MAXN];
double y[MAXN];
int main()
{
int n;
double baseX, baseY;
while (cin >> n)
{
if (n == 0)
break;
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
}
sort(x, x + n);
sort(y, y + n);
if (n % 2 == 0) //n为偶数,取两个中位数的平均数
{
baseX = (x[n / 2] + x[n / 2 - 1]) / 2.0;
baseY = (y[n / 2] + y[n / 2 - 1]) / 2.0;
}
else //n为奇数,取中位数
{
baseX = x[n / 2];
baseY = y[n / 2];
}
cout << fixed << setprecision(2) << baseX << " " << baseY << endl;
}
return 0;
}
继续加油。