题意:和上题一样。。。就是把最小值换成了最大值。。

ref:http://www.cppblog.com/RyanWang/archive/2010/01/21/106112.html

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std; #define eps 1e-3
#define pi acos(-1.0)
#define POI 15 //独立跑POI次,找最值 tp[1..POI]是随机的初值
#define RUN 40 //迭代次数,本题中即点(tx,ty)向RUN个方向发散
#define INF 99999.999
int X,Y,N,T;
double ans;
int ansi;
struct
{
double x,y;
}tp[],hol[];
double sol[]; double dist(double x1,double y1,double x2,double y2)
{
return(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
} double dis(double x,double y)
{
double tmp=INF;
for(int i=;i<=N;i++)
{
double tx=hol[i].x,ty=hol[i].y;
tmp=min(tmp,dist(tx,ty,x,y));
}
return tmp;
} void sa()
{
for(int i=;i<=POI;i++)
{
tp[i].x=(rand()%+)/1000.0*X;
tp[i].y=(rand()%+)/1000.0*Y;
sol[i]=dis(tp[i].x,tp[i].y);
//printf("%.1f~%.1f=%.1f\n",tp[i].x,tp[i].y,sol[i]);
} double step=1.0*max(X,Y)/sqrt(1.0*N);
while(step>eps)
{
for(int i=;i<=POI;i++)
{
double kx=tp[i].x,ky=tp[i].y;
double tx=kx,ty=ky;
for(int j=;j<RUN;j++)
{
double angle=(rand()%+)/1000.0**pi;
kx=tx+cos(angle)*step;
ky=ty+sin(angle)*step;
if((kx>X)||(ky>Y)||(kx<)||(ky<)) continue;
double tmp=dis(kx,ky);
if(tmp>sol[i])
{
tp[i].x=kx; tp[i].y=ky;
sol[i]=tmp;
}
}
}
step*=0.80;
}
} int main()
{
srand(time(NULL));
cin>>T;
//cout<<T<<endl;
while(T--)
{
cin>>X>>Y>>N;
for(int i=;i<=N;i++)
cin>>hol[i].x>>hol[i].y; sa(); ans=0.000;
for(int i=;i<=POI;i++)
{
//printf("AA: %.1f~%.1f=%.1f\n",tp[i].x,tp[i].y,sol[i]);
if(sol[i]>ans)
{
ans=sol[i];
ansi=i;
}
}
printf("The safest point is (%.1f, %.1f).\n",tp[ansi].x,tp[ansi].y);
//printf("%.1lf\n",ans);
}
return ;
}

poj1379 模拟退火的更多相关文章

  1. 【模拟退火】poj1379 Run Away

    题意:平面上找一个点,使得其到给定的n个点的距离的最小值最大. 模拟退火看这篇:http://www.cnblogs.com/autsky-jadek/p/7524208.html 这题稍有不同之处仅 ...

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

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

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

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

  4. poj1379

    poj1379 题意 给出 n 个洞的坐标,要求找到一点使得这一点距离最近洞的距离最远. 分析 通过这道题学习一下模拟退火算法, 这种随机化的算法,在求解距离且精度要求较小时很有用. 简而言之,由随机 ...

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

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

  6. bzoj3680模拟退火

    看题意就是一道数学物理题,带权费马点   --这怎么是数学了,这也是物理的 所以要用物理方法,比如FFF 国际著名oi选手miaom曾说 模拟退火初温可以低,但是最好烧个几千次 国际著名物理课代表+1 ...

  7. 无题的题 & 模拟退火...

    题意: 给你不超过8条一端在圆心的半径,求他们组成的凸包的最大面积. SOL: 正解怎么搞啊不会啊...然后昨天毛爷爷刚讲过模拟退火...那么就打一个吧... 然后就T了,不过三角形的部分分妥妥的.. ...

  8. [POJ2069]Super Star(模拟退火)

    题目链接:http://poj.org/problem?id=2069 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移 ...

  9. [POJ2420]A Star not a Tree?(模拟退火)

    题目链接:http://poj.org/problem?id=2420 求费马点,即到所有其他点总和距离最小的点. 一开始想枚举一个坐标,另一个坐标二分的,但是check的时候还是O(n)的,复杂度相 ...

随机推荐

  1. How To Create an IE-Only Stylesheet

    https://css-tricks.com/how-to-create-an-ie-only-stylesheet/ https://css-tricks.com/snippets/css/css- ...

  2. Construct Binary Tree from Preorder and Inorder Traversal

    Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...

  3. weblogic.nodemanager.common.ConfigException: Native version is enabled but nodemanager native library could not be loaded 解决办法

    近日在一个原本工作正常的weblogic web server(操作系统为redhat 64位系统)上折腾安装redis/hadoop等东东,yum install了一堆第3方类库后,重启weblog ...

  4. es6+react环境搭建

    工具说明 Node Koa React Webpack 项目结构 - build 客户端代码的构建文件目录 - config 项目的配置文件 - docs 项目相关的文档目录 - lib 服务端库文件 ...

  5. CUDA2.1-原理之索引与warp

    本小节来自<大规模并行处理器编程实战>第四节,该书是很好的从内部原理结构上来讲述了CUDA的,对于理解CUDA很有帮助,借以博客的形式去繁取间,肯定会加入自己个人理解,所以有错误之处还望指 ...

  6. JavaScript Array

    1.常用方法 // 数组构造 var a = new Array(20); // 长度为20的数组 var b = new Array('red', 'blue', 'white'); var c = ...

  7. HTML5+JS 《五子飞》游戏实现(一)规则

    很久没写文章了,这个游戏其实已经写了有段时间了,一直没有完善,赶在新年之际,分享给大家. 该<五子飞>游戏,不是平常大家所说的<五子棋>,这个玩法简单,是我们老家儿时常玩的一种 ...

  8. NHibernate无法将类型“System.Collections.Generic.IList<T>”隐式转换为“System.Collections.Generic.IList<IT>

    API有一个需要实现的抽象方法: public IList<IPermission> GetPermissions(); 需要注意的是IList<IPermission>这个泛 ...

  9. Java序列化中的SerialVersionUid

    版权声明:本文为博主fbysss原创文章,转载请注明出处 作者:fbysssmsn:jameslastchina@hotmail.com  blog:blog.csdn.NET/fbysss声明:本文 ...

  10. AJAX——核心XMLHttpRequest对象

    AJAX大家已经都知道了,是为了实现异步通讯,提高用户体验度,而将很多旧知识(XML,DOM,JavaScript,HTML,Jquery,Css……)重新融合的一个新的知识框架.而,XMLHttpR ...