题意:平面上找一个点,使得其到给定的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. zabbix的命令执行

    1.对于低版本的可用下列exp直接打到用户 http://119.29.48.232/zabbix/httpmon.php?applications=2 and (select 1 from (sel ...

  2. 01背包问题的延伸即变形 (dp)

    对于普通的01背包问题,如果修改限制条件的大小,让数据范围比较大的话,比如相比较重量而言,价值的范围比较小,我们可以试着修改dp的对象,之前的dp针对不同的重量限制计算最大的价值.这次用dp针对不同的 ...

  3. javascript 事件知识集锦

    1.事件委托极其应用 转载的链接:  http://www.webhek.com/event-delegate/#comments 2. 解析javascript事件机制 转载链接:    http: ...

  4. bzoj 1006 MCS算法

    根据陈丹琪的论文弦图与区间图,求出弦图的完美消除序列之后,反向给每个点染可以染的最小的颜色,这样可以使用最少的颜色染色,染色的方案即为队伍数. 那么我们需要求该图的完美消除序列,使用MCS算法,从后向 ...

  5. Win10默认浏览器怎么设置

    1.首先在Win10桌面左下角的开始菜单图标上右键单击鼠标,在弹出的菜单选项中,点击进入“控制面板”,如下图所示. 接下来就可以找到“默认程序”设置了,找到后点击进入设置,如下图所示. 打开Win10 ...

  6. Linux内核模块编程可以使用的内核组件

    2.2.2 在阅读<深入Linux内核架构与底层原理> 作者:刘京洋 韩方,发现一些错误,有些自己的理解,特以此记录 1.工作队列(workqueue) 队列是一种可以先进先出的数据结构, ...

  7. Vim中的键映射【转】

    转自:http://www.cnblogs.com/softwaretesting/archive/2011/09/28/2194515.html http://www.pythonclub.org/ ...

  8. 【bzoj1068】【SCOI2007】压缩

    一道区间dp f[i][j][0/1]表示[i,j]区间是否加入M,并且之前一位有M的最小长度 可以理解为在第一位之前有一个M 那么就可以转移了. #include<bits/stdc++.h& ...

  9. 【bzoj1026】windy数

    江泽OJ好,远离bzoj保平安. 仍然沿用之前的记忆化搜索的办法即可. #include<bits/stdc++.h> #define N 10010 using namespace st ...

  10. HEER-Easing Embedding Learning by Comprehensive Transcription of Heterogeneous Information Networks

    来源:KDD 2018 原文:HEER code:https://github.com/GentleZhu/HEER 注: 若有错误,欢迎指正   这篇KDD’18的文章,没有按照常规的方法将所有的n ...