HDU3932
题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小
简单的模拟退火即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm> using namespace std; #define N 1005
#define PI acos(-1.0)
#define random(x) (rand()%x+1)
const int P = ;
const int L = ;
double X,Y;
int n;
double mindis[N]; struct Point{
double x , y;
Point(double x= , double y=):x(x),y(y){}
void input(){
scanf("%lf%lf" , &x , &y);
}
}p[N] , tmp[N]; double dis(Point a , Point b)
{
double x = a.x-b.x , y=a.y-b.y;
return sqrt(x*x+y*y);
} double cal(Point a)
{
double maxn = ;
for(int i= ; i<n ; i++) maxn = max(maxn , dis(a , p[i]));
return maxn;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in" , "r" , stdin);
#endif // ONLINE_JUDGE
while(~scanf("%lf%lf%d" , &X , &Y , &n))
{
for(int i= ; i<n ; i++) p[i].input();
for(int i= ; i<P ; i++){
tmp[i].x = random()/1000.0*X;
tmp[i].y = random()/1000.0*Y;
mindis[i] = cal(tmp[i]);
}
double step = sqrt(X*X+Y*Y)/;
while(step>1e-){
for(int i= ; i<P ; i++){
for(int j= ; j<L ; j++){
Point cur;
double ang = random()/1000.0**PI;
cur.x = tmp[i].x+cos(ang)*step;
cur.y = tmp[i].y+sin(ang)*step;
if(cur.x< || cur.x>X || cur.y< || cur.y>Y) continue;
double val = cal(cur);
if(val<mindis[i]){
mindis[i] = val;
tmp[i] = cur;
}
}
}
step *= 0.85;
}
double ret = 1e20;
Point u;
for(int i= ; i<P ; i++){
if(mindis[i]<ret){
u = tmp[i];
ret = mindis[i];
}
}
printf("(%.1f,%.1f).\n%.1f\n" , u.x,u.y,ret);
}
return ;
}