poj_2069_Super Star_WA

#include<iostream>    
#include<sstream>    
#include<string>    
#include<vector>    
#include<list>    
#include<set>    
#include<map>  
#include<stack>    
#include<queue>    
#include<algorithm>    
#include<numeric>    
#include<cmath>  
#include<cstdio>  
#include<cstdlib>  
#include<cstring>
#include<ctime>
#pragma warning(disable:4996) 
const double EPS = 1e-15;
const double rate = 0.9995;
#define INF 2000000000
#define PI acos(-1.0)
const int N = 30;
const int M = 30;
using namespace std;
class Point
{
public:
	double x, y, z;
};
double dist(const Point &p1, const Point &p2)
{
	return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y) + (p1.z - p2.z)*(p1.z - p2.z));
}
double getMaxDist(const Point&p, const vector<Point>&point)
{
	double ans = 0.0;
	for (size_t i = 0; i != point.size(); i++)
	{
		ans = max(ans, dist(p, point[i]));
	}
	return ans;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand((unsigned)time(NULL));
	int n;
	while (cin >> n&&n)
	{
		vector<Point>point(n);
		double max_x = -2000000000.0, max_y = -2000000000.0, max_z = -2000000000.0;
		double min_x = 2000000000.0, min_y = 2000000000.0, min_z = 2000000000.0;
		for (int i = 0; i < n; i++)
		{
			cin >> point[i].x >> point[i].y >> point[i].z;
			max_x = max(max_x, point[i].x);
			max_y = max(max_y, point[i].y);
			max_z = max(max_z, point[i].z);
			min_x = min(min_x, point[i].x);
			min_y = min(min_y, point[i].y);
			min_z = min(min_z, point[i].z);
		}
		Point curpoint;
		curpoint.x = (max_x - min_x) / 2.0;
		curpoint.y = (max_y - min_y) / 2.0;
		curpoint.z = (max_z - min_z) / 2.0;
		double delta = 100;
		double ans = getMaxDist(curpoint, point);
		while (delta > 1e-15)
		{
			double theta1 = (double)(rand() % 1000) / 1000.0*2.0*PI;
			double theta2 = (double)(rand() % 1000) / 1000.0*2.0*PI;
			Point nextpoint;
			nextpoint.x = curpoint.x + cos(theta1)*cos(theta2)*delta;
			nextpoint.y = curpoint.y + cos(theta1)*sin(theta2)*delta;
			nextpoint.z = curpoint.z + sin(theta1)*delta;
			double distance = getMaxDist(nextpoint, point);
			if (distance < ans)
			{
				curpoint = nextpoint;
				ans = distance;
			}
			delta *= rate;
		}
		printf("%.5lf\n", ans);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值