poj 1379 Run Away

06年论文里的题

正解是voronoi图

然而我看了半天也不会QAQ

构造算法太复杂了

然后写了个模拟退火水一水。。。。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
double sqr(double x){return x*x;}
const double pi=acos(-1.0);
const double eps=1e-9;
struct point{
	double x,y;
}p[1005],xx[30];
double bx[30];
int n;
double dist(point a,point b){
	return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
double calc(point a){
	double ans=dist(p[1],a);
	for(int i=2;i<=n;i++)
	ans=min(ans,dist(p[i],a));
	return ans;
}
double x,y;
bool in(point p){
	return p.x>-eps&&p.x<x+eps&&p.y>-eps&&p.y<y+eps;
}
int main(){
	//freopen("a.in","r",stdin);
	//srand(time(0));
	int Cas;
	scanf("%d",&Cas);
	while(Cas--){
		scanf("%lf%lf%d",&x,&y,&n);
		for(int i=1;i<=n;i++)
		scanf("%lf%lf",&p[i].x,&p[i].y);
		for(int i=1;i<=17;i++){
			xx[i].x=(rand()%1000+1)/1000.0*x;
			xx[i].y=(rand()%1000+1)/1000.0*y;
			bx[i]=calc(xx[i]);
		}
		double T=max(x,y)/sqrt(1.0*n);
		while(T>1e-3){
			for(int i=1;i<=17;i++){
				point now,last=xx[i];
				for(int j=1;j<=31;j++){
					double angle=(rand()%1000+1)/1000.0*2*pi;
					now.x=last.x+cos(angle)*T;
					now.y=last.y+sin(angle)*T;
					if(!in(now))continue;
					double tmp=calc(now);
					if(tmp>bx[i]){
						bx[i]=tmp;
						xx[i]=now;
					}
				}
			}
			T*=0.83;
		}
		int id=0;
		double ans=0;
		for(int i=1;i<=17;i++)
		if(bx[i]>ans){
			ans=bx[i];
			id=i;
		}
		printf("The safest point is (%.1f, %.1f).\n",xx[id].x,xx[id].y);
	}
	return 0;
}
 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值