题意:平面上找一个点,使得其到给定的n个点的距离的最小值最大。

模拟退火看这篇:http://www.cnblogs.com/autsky-jadek/p/7524208.html

这题稍有不同之处仅有:多随机几个初始点,以增加正确率。

另:WA了几百遍竟然是因为最后输出了-0.0这样的值……

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
const double EPS=0.00000001;
const double PI=acos(-1.0);
struct Point{
double x,y;
Point(const double &x,const double &y){
this->x=x;
this->y=y;
}
Point(){}
void read(){
scanf("%lf%lf",&x,&y);
}
double length(){
return sqrt(x*x+y*y);
}
}a[1005],p,allp;
double ans,allans;
int n,X,Y;
typedef Point Vector;
Vector operator - (const Point &a,const Point &b){
return Vector(a.x-b.x,a.y-b.y);
}
Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x+b.x,a.y+b.y);
}
Vector operator * (const double &K,const Vector &v){
return Vector(K*v.x,K*v.y);
}
double calc(Point p){
double res=1000000.0;
for(int i=1;i<=n;++i){
res=min(res,(a[i]-p).length());
}
return res;
}
int main(){
int zu;
srand(233);
//freopen("poj1379.in","r",stdin);
//freopen("poj1379.out","w",stdout);
scanf("%d",&zu);
for(;zu;--zu){
allans=0.0;
scanf("%d%d%d",&X,&Y,&n);
p=Point(0.0,0.0);
for(int i=1;i<=n;++i){
a[i].read();
}
for(int j=1;j<=15;++j){
p.x=(double)(rand()%(X+1));
p.y=(double)(rand()%(Y+1));
ans=calc(p);
double T=sqrt((double)X*(double)X+(double)Y*(double)Y)/2.0;
// double T=(double)max(X,Y)/sqrt((double)n);
while(T>EPS){
double bestnow=0.0;
Point besttp;
for(int i=1;i<=35;++i){
double rad=(double)(rand()%10000+1)/10000.0*2.0*PI;
Point tp=p+T*Point(cos(rad),sin(rad));
if(tp.x>-EPS && tp.x-(double)X<EPS && tp.y>-EPS && tp.y-(double)Y<EPS){
double now=calc(tp);
if(now>bestnow){
bestnow=now;
besttp=tp;
}
}
}
if(bestnow>EPS && (bestnow>ans || exp((bestnow-ans)/T)*10000.0>(double)(rand()%10000))){
ans=bestnow;
p=besttp;
}
T*=0.9;
}
if(ans>allans){
allans=ans;
allp=p;
}
}
printf("The safest point is (%.1f, %.1f).\n",fabs(allp.x),fabs(allp.y));
}
return 0;
}

【模拟退火】poj1379 Run Away的更多相关文章

  1. poj-1379 Run Away(模拟退火算法)

    题目链接: Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7982   Accepted: 2391 De ...

  2. poj1379 Run Away

    传送门:http://poj.org/problem?id=1379 [题解] 题目大意:求(0,0)->(X,Y)内的一个点,使得这个点到给定的n个点的最小距离最大. 模拟退火 一开始可以先把 ...

  3. 模拟退火算法(run away poj1379)

    http://poj.org/problem?id=1379 Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: ...

  4. 【BZOJ1844/2210】Pku1379 Run Away 模拟退火

    [BZOJ1844/2210]Pku1379 Run Away 题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大. 题解:模拟退火的裸题,再调调调调调参就行了~ #inclu ...

  5. poj1379 模拟退火

    题意:和上题一样...就是把最小值换成了最大值.. ref:http://www.cppblog.com/RyanWang/archive/2010/01/21/106112.html #includ ...

  6. POJ 1379 Run Away 【基础模拟退火】

    题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...

  7. Run Away 模拟退火

    Run Away Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  8. PKU 1379 Run Away(模拟退火算法)

    题目大意:原题链接 给出指定的区域,以及平面内的点集,求出一个该区域内一个点的坐标到点集中所有点的最小距离最大. 解题思路:一开始想到用随机化算法解决,但是不知道如何实现.最后看了题解才知道原来是要用 ...

  9. poj 1379 Run Away 模拟退火 难度:1

    Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6482   Accepted: 1993 Descript ...

随机推荐

  1. Little Mathematics Knowledge 数学小常识

    The sum of arithmetic sequence The sum of geometric sequence A special formula : n·n! = (n+1)! - n! ...

  2. CSS 竖线颜色渐变

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"& ...

  3. bzoj 2165 DP

    首先如果不考虑数据范围的话,因为每一层都是等效的,所以我们可以用w[i][j][k]来表示在某一层的j位置,称作i次电梯到k位置,最多上升多少层,那么我们可以比较容易的写出转移,因为m十分大,i可能与 ...

  4. handle_level_irq 与handle_edge_irq 的区别【转】

    转自:http://blog.csdn.net/xavierxiao/article/details/6087277 版权声明:本文为博主原创文章,未经博主允许不得转载. Linux 里, handl ...

  5. Laravel 5.2 三、中间件、视图与 Blade 模板引擎

    一.中间件 Laravel 的 HTTP 中间件提供了对路由的一层过滤和保护.下面模拟一下用中间件验证后台登录. 1. 创建中间件 cmd 窗口进入项目目录,使用 artisan 命令创建 php a ...

  6. python基础===PEP网站,代码规范指南

    PEP 8是最古老的PEP之一,它向Python程序员提供了代码格式设置指南.PEP 8的篇幅很长,但大都与复杂的编码结构相关. https://python.org/dev/peps/pep-000 ...

  7. linux 系统调用exec()

    系统调用execve()对当前进程进行替换,替换者为一个指定的程序,其参数包括文件名(filename).参数列表(argv)以及环境变量(envp).exec函数族当然不止一个,但它们大致相同,在 ...

  8. laravel 中的入口文件报错

    1.此次是由于加载的配置文件的编码错误导致的.例:conf.php

  9. python插入oracle数据

    # coding=utf- ''''' Created on -- @author: ''' import json; import urllib2 import sys import cx_Orac ...

  10. leetcode 之Reverse Linked List II(15)

    这题用需要非常细心,用头插法移动需要考虑先移动哪个,只需三个指针即可. ListNode *reverseList(ListNode *head, int m, int n) { ListNode d ...