题意:平面上找一个点,使得其到给定的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. POJ 2991 Crane (线段树)

    题目链接 Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of v ...

  2. 在电脑中配置adb

    在环境变量的系统变量path中添加SDK中platform_tools和tools的路径 如果出现version说明配置成功

  3. Android中的异常情况

    1.setText()方法中,如果参数是int类型,Android会把它当做是一个id查找,报以下异常,因此解决办法就是将参数转化为String类型 如:setText(num) è setText( ...

  4. CentOS7安装MySQL5.7以及修改密码

    CentOS7安装mysql [root@bd005 ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch. ...

  5. SQL利用Case When Then多条件判断SQL 语句

    http://www.cnblogs.com/kevin2013/archive/2010/07/02/1769682.html SQL利用Case When Then多条件判断SQL ,用于sele ...

  6. An In-Depth Look at the HBase Architecture

    https://www.mapr.com/blog/in-depth-look-hbase-architecture An In-Depth Look at the HBase Architectur ...

  7. linux命令--head

    head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 具体使用参考链接: h ...

  8. [ 总结 ] Linux系统启动流程

    Linux系统启动过程分析: 按下电源 --> BIOS自检 --> 系统引导(lilo/grub) --> 启动内核 --> 初始化系统 --> 用户登录 1. BIO ...

  9. ip和子网掩码的判断

     只要记住B类IP的范围就好了(128以下的是A,128~191是B段,192以上是C段) 比如B类,网络地址为前两段,后面两段是主机地址,所以网络标识应该是255.255.0.0

  10. 【python】pymongo中正则查询时的转义问题

    在查询mongo时用到了正则查询 设字符串为   str = '/ab/cd.ef?g=' 直接用正则查询没有匹配. collection.find({"re":{'$regex' ...