【BZOJ1844/2210】Pku1379 Run Away

题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大。

题解:模拟退火的裸题,再调调调调调参就行了~

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
const int maxn=1010;
struct pdd
{
double x,y;
pdd() {}
pdd(double a,double b) {x=a,y=b;}
}p[maxn];
int n;
double X,Y,T,mx;
pdd ans,now,neo;
double getdis(pdd a,pdd b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-')f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();
return ret*f;
}
double solve(pdd a)
{
double ret=1e10;
for(int i=1;i<=n;i++) ret=min(ret,getdis(a,p[i]));
if(ret>mx) mx=ret,ans=a;
return ret;
}
double Rand()
{
return rand()%1000/1000.0;
}
void work()
{
X=rd(),Y=rd(),n=rd();
int i,j;
for(i=1;i<=n;i++) p[i].x=rd(),p[i].y=rd();
mx=0;
for(j=1;j<=50;j++)
{
now.x=Rand()*X,now.y=Rand()*Y,solve(now),T=1000;
while(T>1e-3)
{
double a=2.0*acos(-1.0)*Rand();
neo.x=now.x+T*cos(a),neo.y=now.y+T*sin(a),T*=0.95;
if(neo.x<0||neo.x>X||neo.y<0||neo.y>Y) continue;
double de=solve(neo)-solve(now);
if(de>0) now=neo;
}
T=0.5;
for(i=1;i<=500;i++)
{
double a=2.0*acos(-1.0)*Rand();
neo.x=now.x+T*cos(a);
neo.y=now.y+T*sin(a);
if(neo.x<0||neo.x>X||neo.y<0||neo.y>Y) continue;
solve(neo);
}
}
printf("The safest point is (%.1lf, %.1lf).\n",ans.x,ans.y);
}
int main()
{
srand(2333666);
int T=rd();
while(T--) work();
}

【BZOJ1844/2210】Pku1379 Run Away 模拟退火的更多相关文章

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

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

  2. Run Away 模拟退火

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

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

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

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

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

  5. POJ.1379.Run Away(模拟退火)

    题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...

  6. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  7. 一文搞懂GitLab安装部署及服务配置

    GitLab安装部署 Git,GitHub,GitLab,这三个东东长得好像呀,都是个啥? Git是Linus Torvalds(如果不知道这位大神是谁,请出门左转,慢走不送~)为了帮助管理Linux ...

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

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

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

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

随机推荐

  1. hdu 4305 生成树计数问题

    Lightning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu 1979 剪枝暴搜

    Fill the blanks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. 切糕(bzoj 3144)

    Description Input 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的矩阵,第z个 矩阵的第x行第y列是v(x, ...

  4. http client transfer

    背景 在平时工作中我偶尔会写一些脚本监控HTTP接口的健康状况,基本上都是发送HTTP GET或HTTP POST请求,然后检测响应内容.但一直用的是WebClient和HttpWebRequest, ...

  5. 学习javascript设计模式之中介者模式

    1.中介者模式的作用就是解除对象与对象之间的紧耦合关系.增加一个中介者对象后,所有的相关对象都通过中介者来通信,而不是互相引用,所以当一个对象发生改变时,只需要通知中介对象即可.中介者使各对象之间耦合 ...

  6. LeetCode OJ--Permutations *

    https://oj.leetcode.com/problems/permutations/ 写出一列数的全排列 #include <iostream> #include <vect ...

  7. iphoneXR的tabbar底部图片的适配

    在自定义tabbar的背景图时,发现在ihonexr上有点问题,主要是因为iphoneXr用的是二倍图,但是Xr的tabbar底部高度多了34像素,所以就出现了如下的情况: 解决这个问题,还比较简单, ...

  8. Codeforces 919 C. Seat Arrangements

    C. Seat Arrangements   time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. 可能是全网最详细的express--middleware

    写在前面 hello,小伙伴们,我是你们的pubdreamcc,本篇博文出至于我的GitHub仓库node学习教程资料,欢迎小伙伴们点赞和star,你们的点赞是我持续更新的动力. GitHub仓库地址 ...

  10. python pip包管理器安装

    下载   http://peak.telecommunity.com/dist/ez_setup.py 执行:python ez_setup.py 下载:  http://pypi.python.or ...