1773.cpp

来自「哈尔滨工业大学ACM 竞赛网上在线试题集锦的源代码」· C++ 代码 · 共 51 行

CPP
51
字号
/*  This Code is Submitted by wywcgs for Problem 1773 on 2006-02-24 at 12:17:20 */ 
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX = 1024;
const double INF = 1e10;

class Point {
private:
	double lat, lon;
public:
	double x, y, z;
	void make();
	double dis(const Point&) const;
	void print() const;
};
void Point::make() {
	scanf("%lf %lf", &lat, &lon);
	double i = lon * M_PI / 180, j = lat * M_PI / 180;
	double cosB = cos(j);
	x = cos(i) * cosB; y = sin(i) * cosB; z = sin(j);
}
double Point::dis(const Point& p) const {
	return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z));
}
void Point::print() const {
	printf("%.2lf %.2lf\n", lat, lon);
}

int main()
{
	int i, j, n;
	Point port[MAX];

	while(scanf("%d", &n) != EOF) {
		for(i = 0; i < n; i++) port[i].make();
		double dis = INF; int o;
		for(i = 0; i < n; i++) {
			double m = 0;
			for(j = 0; j < n; j++)
				if(i != j) m = max(m, port[i].dis(port[j]));
			if(m < dis) dis = m, o = i;
		}
		port[o].print();
	}

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?