#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;
}
hdu_3932_Groundhog Build Home
最新推荐文章于 2018-11-01 10:10:33 发布