http://poj.org/problem?id=1379

Run Away
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 6095   Accepted: 1869

Description

One of the traps we will encounter in the Pyramid is located in the Large Room. A lot of small holes are drilled into the floor. They look completely harmless at the first sight. But when activated, they start to throw out very hot java, uh ... pardon, lava.
Unfortunately, all known paths to the Center Room (where the Sarcophagus is) contain a trigger that activates the trap. The ACM were not able to avoid that. But they have carefully monitored the positions of all the holes. So it is important to find the place
in the Large Room that has the maximal distance from all the holes. This place is the safest in the entire room and the archaeologist has to hide there.

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing three integers X, Y, M separated by space. The numbers satisfy conditions: 1 <= X,Y <=10000, 1 <= M <= 1000.
The numbers X and Yindicate the dimensions of the Large Room which has a rectangular shape. The number M stands for the number of holes. Then exactly M lines follow, each containing two integer numbers Ui and Vi (0 <= Ui <= X, 0 <= Vi <= Y) indicating the
coordinates of one hole. There may be several holes at the same position.

Output

Print exactly one line for each test case. The line should contain the sentence "The safest point is (P, Q)." where P and Qare the coordinates of the point in the room that has the maximum distance from the nearest hole, rounded to the nearest number with exactly
one digit after the decimal point (0.05 rounds up to 0.1).

Sample Input

3
1000 50 1
10 10
100 100 4
10 10
10 90
90 10
90 90
3000 3000 4
1200 85
63 2500
2700 2650
2990 100

Sample Output

The safest point is (1000.0, 50.0).
The safest point is (50.0, 50.0).
The safest point is (1433.0, 1669.8).

题意:给出一个矩形的范围和其中的n个点,问,在这个矩形内距离这n个点的最近距离最远的坐标是多少;

分析:首先在<X,Y>范围内随机出op个可能的局部最优解,然后对于每个随机出来的点在进行任意方向的扩展(利用随机弧度实现);

#include"string.h"
#include"stdio.h"
#include"queue"
#include"stack"
#include"vector"
#include"algorithm"
#include"iostream"
#include"math.h"
#include"stdlib.h"
#define M 1010
#define inf 100000000000
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
struct node
{
double x,y,dis;
}p[M],q[50],d[50];
double X,Y;
int n;
double min(double a,double b)
{
return a<b?a:b;
}
double max(double a,double b)
{
return a>b?a:b;
}
double pow(double x)
{
return x*x;
}
double len(double x1,double y1,double x2,double y2)
{
return pow(x1-x2)+pow(y1-y2);
}
double fun(double x,double y)
{
double mini=inf;
for(int i=1;i<=n;i++)
{
double L=len(x,y,p[i].x,p[i].y);
if(mini>L)
mini=L;
}
return mini;
}
void solve()
{
int po=15,est=25,i,j;
for(i=1;i<=po;i++)
{
q[i].x=(rand()%1000+1)/1000.0*X;
q[i].y=(rand()%1000+1)/1000.0*Y;
q[i].dis=fun(q[i].x,q[i].y);
}
double temp=sqrt(X*X+Y*Y);
double rate=0.9;
while(temp>eps)
{
for(i=1;i<=po;i++)
{
for(j=1;j<=est;j++)
{
double rad=(rand()%1000+1)/1000.0*PI*10;
node now;
now.x=q[i].x+temp*cos(rad);
now.y=q[i].y+temp*sin(rad);
if(now.x<0||now.x>X||now.y<0||now.y>Y)continue;
now.dis=fun(now.x,now.y);
if(now.dis>q[i].dis)
q[i]=now;
}
}
temp*=rate;
}
int indx=1;
for(i=1;i<=po;i++)
{
if(q[i].dis>q[indx].dis)
indx=i;
}
printf("The safest point is (%.1lf, %.1lf).\n",q[indx].x,q[indx].y);
}
int main()
{
int T,i;
cin>>T;
while(T--)
{
scanf("%lf%lf%d",&X,&Y,&n);
for(i=1;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
solve();
}
}

模拟退火算法(run away poj1379)的更多相关文章

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

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

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

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

  3. poj-2420 A Star not a Tree?(模拟退火算法)

    题目链接: A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5219   Accepte ...

  4. 模拟退火算法-[HDU1109]

    模拟退火算法的原理模拟退火算法来源于固体退火原理,将固体加温至充分高,再让其徐徐冷却,加温时,固体内部粒子随温升变为无序状,内能增大,而徐徐冷却时粒子渐趋有序,在每个温度都达到平衡态,最后在常温时达到 ...

  5. 【高级算法】模拟退火算法解决3SAT问题(C++实现)

    转载请注明出处:http://blog.csdn.net/zhoubin1992/article/details/46453761 ---------------------------------- ...

  6. 模拟退火算法(SA)求解TSP 问题(C语言实现)

    这篇文章是之前写的智能算法(遗传算法(GA).粒子群算法(PSO))的补充.其实代码我老早之前就写完了,今天恰好重新翻到了,就拿出来给大家分享一下,也当是回顾与总结了. 首先介绍一下模拟退火算法(SA ...

  7. 原创:工作指派问题解决方案---模拟退火算法C实现

    本文忽略了对于模拟退火的算法的理论讲解,读者可参考相关的博文或者其他相关资料,本文着重于算法的实现: /************************************************ ...

  8. BZOJ 3680: 吊打XXX【模拟退火算法裸题学习,爬山算法学习】

    3680: 吊打XXX Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 3192  Solved: 1198[Sub ...

  9. OI骗分神器——模拟退火算法

    前言&&为什么要学模拟退火 最近一下子学了一大堆省选算法,所以搞一个愉快一点的东西来让娱乐一下 其实是为了骗到更多的分,然后证明自己的RP. 说实话模拟退火是一个集物理与IT多方面知识 ...

  10. 模拟退火算法 R语言

    0 引言 模拟退火算法是用来解决TSP问题被提出的,用于组合优化. 1 原理 一种通用的概率算法,用来在一个打的搜索空间内寻找命题的最优解.它的原理就是通过迭代更新当前值来得到最优解.模拟退火通常使用 ...

随机推荐

  1. easyui Datagrid+searchbox 实现搜索功能

    1.前台页面 <%@ page language="java" pageEncoding="utf-8" isELIgnored="false& ...

  2. VMware ESXi 不支持NTFS格式的USB外接硬盘

    本来想搞直通USB外接大容量硬盘(希捷Seagate Backup+ Hub WH 8T),实现在同一部ESXi下,直接将NAS的数据转移到外接硬盘.结果发现虚拟机下的win server系统识别不了 ...

  3. 【转】 如何利用C#代码来进行操作AD

    要用代码访问 Active Directory域服务,需引用System.DirectoryServices命名空间,该命名空间包含两个组件类,DirectoryEntry和 DirectorySea ...

  4. 关掉firefox(火狐)和palemoon地址栏自动加www.前缀功能【转】

    常用palemoon调试网站域名,它会很“贴心”的给你输入的网址前加上www.前缀,可有些域名前并没有www前缀,这样就导致了无法打开网站,今天学习下关闭它的这个功能. 打开firefox,在地址栏输 ...

  5. 【R】shiny界面

    http://www.rstudio.com/shiny http://yanping.me/shiny-tutorial/#welcome

  6. jquery注册文本框获取焦点清空,失去焦点赋值的简单实例

    在我们开发过程中特别是用户注册时会有一个效果,就是文本框获取焦点清空提示,如果用户没有输入信息失去焦点赋值上我们的提示语.   <html> <head> <meta h ...

  7. Unity3D面试——真实的面试,unity3d面试

    本来想写一个系列的,一半是抨击现在面试之水,要人之奸,用大哥的话说,要走新手是做螺丝钉和抹布用的.另一半是对出出学校的或者是自废武功转3d的朋友们提供一个比较有价值的参考.不过我时间实在仓促.没有保证 ...

  8. 二:Java之异常处理

    一.异常的概念 异常,也就是非正常情况. 其实.异常本质上是程序上的错误,包含程序逻辑错误和系统错误. 错误在我们编敲代码的过程中会常常发生,包含编译期间和执行期间的错误,在编译期间出现的错误有编译器 ...

  9. Animy.js,自己编写的功能丰富的html动画库

    近期由于项目须要.本人制作了一款js的动画插件.能够用于完毕各种js动画.比方移动.拉升.变色等等,全部动画经常使用的功能都已经实现,比方播放.暂停.停止.循环.加速.减速.反向播放.缓动.路径动画. ...

  10. easyui------修改validatebox过滤规则

    转载: http://www.cnblogs.com/zhxhdean/archive/2011/09/21/2184153.html 代码: //扩展easyui表单的验证 $.extend($.f ...