hdu_3932_Groundhog Build Home

#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)   
#define EPS 1e-8  
#define INF 2000000000  
#define PI acos(-1.0)  
const int N = 40;
const int M = 40;
using namespace std;
double X, Y;
class Point
{
public:
	double x, y;
	bool isIn()
	{
		if (x > -EPS&&x<EPS + X&&y>-EPS&&y < EPS + Y)
		{
			return true;

		}
		return false;
	}
};
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));
}
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(point[i], p));
	}
	return ans;
}
int main()
{
	//freopen("input.txt", "r", stdin);  
	//freopen("output.txt", "w", stdout);  
	srand((unsigned)time(NULL));
	while (cin >> X)
	{
		int n;
		cin >> Y >> n;
		vector<Point>trap(n);//各陷阱的坐标  
		for (int i = 0; i < n; i++)
		{
			cin >> trap[i].x >> trap[i].y;
		}
		//随机取各随机位置的坐标,并求得到该位置到离它最远的陷阱的距离  
		vector<Point>random(N);
		vector<double>maxdist(N);
		for (int i = 0; i < N; i++)
		{
			random[i].x = (rand() % 10000) / 10000.0*X;
			random[i].y = (rand() % 10000) / 10000.0*Y;
			maxdist[i] = getMaxDist(random[i], trap);
		}
		double delta = max(X, Y) / (double)n;
		while (delta > 1e-3)
		{
			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < M; j++)
				{
					double theta = (rand() % 10000) / 10000.0 * 2 * PI;
					Point nextpoint;
					nextpoint.x = random[i].x + cos(theta)*delta;
					nextpoint.y = random[i].y + sin(theta)*delta;
					if (!nextpoint.isIn()) continue;
					double tmp = getMaxDist(nextpoint, trap);
					if (tmp < maxdist[i])
					{
						random[i] = nextpoint;
						maxdist[i] = tmp;
					}
				}
			}
			delta *= 0.85;
		}
		int index = 0;
		double ans = 2000000000.0;
		for (int i = 0; i < N; i++)
		{
			if (maxdist[i] < ans)
			{
				ans = maxdist[i];
				index = i;
			}
		}
		printf("(%.1lf,%.1lf).\n%.1lf\n", random[index].x, random[index].y, maxdist[index]);
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值