题目链接:

Run Away

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 7982   Accepted: 2391

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).
题意:求矩形里的一个点,使这个点到所有已知点的最小距离尽量大;
思路:看网上说是一个模拟退火算法就简单的学了一下,随机取一些点然后在这些点一点范围内再随机的取点,取得点更符合就更新,指导温度冷却到一定程度就可以得到答案了;
AC代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <algorithm>
using namespace std;
const int num=;//每次的子集有多少元素,就是你要选多少个点进行迭代
const int cnt=;//每次一个点要随机的生成多少个点
const double inf=1e14+;
const double PI=acos(-1.0);
int fx,fy,n;
double x[],y[],px,py;
struct node
{
double X,Y,dis;
};
node ans[];
double get_dis(double a,double b,double c,double d)
{
return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}
void Iint()
{
for(int i=;i<num;i++)
{
ans[i].X=1.0*(rand()%+)/*fx;
ans[i].Y=1.0*(rand()%+)/*fy;
ans[i].dis=inf;
for(int j=;j<n;j++)
{
ans[i].dis=min(ans[i].dis,get_dis(ans[i].X,ans[i].Y,x[j],y[j]));
}
}
}
int main()
{
int t;
scanf("%d",&t);
srand((unsigned)time(NULL));
while(t--)
{
scanf("%d%d%d",&fx,&fy,&n);
for(int i=;i<n;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
Iint();
double temp=max(fx*1.0,fy*1.0)/(sqrt(1.0*n));
while(temp>=0.001)
{
for(int i=;i<num;i++)
{
px=ans[i].X;
py=ans[i].Y;
for(int j=;j<cnt;j++)
{
double s=PI**(rand()%)/,dx,dy;
dx=px+cos(s)*temp;
dy=py+sin(s)*temp;
if(dx<||dx>fx*1.0||dy<||dy>fy*1.0)continue;
double cur=inf;
for(int k=;k<n;k++)
{
cur=min(cur,get_dis(dx,dy,x[k],y[k]));
}
if(cur>ans[i].dis)
{
ans[i].X=dx;
ans[i].Y=dy;
ans[i].dis=cur;
}
} }
temp*=0.83;
}
double ans_dis=,ans_x,ans_y;
for(int i=;i<num;i++)
{
if(ans[i].dis>ans_dis)
{
ans_x=ans[i].X;
ans_y=ans[i].Y;
ans_dis=ans[i].dis;
}
}
printf("The safest point is (%.1lf, %.1lf).\n",ans_x,ans_y);
}
return ;
}

poj-1379 Run Away(模拟退火算法)的更多相关文章

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

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

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

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

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

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

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

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

  5. POJ 1379 Run Away

    题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...

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

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

  7. POJ 1379 模拟退火

    模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...

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

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

  9. 初探 模拟退火算法 POJ2420 HDU1109

    模拟退火算法来源于固体退火原理,更多的化学物理公式等等这里不再废话,我们直接这么来看 模拟退火算法简而言之就是一种暴力搜索算法,用来在一定概率下查找全局最优解 找的过程和固体退火原理有所联系,一般来讲 ...

随机推荐

  1. 【文献阅读】Self-Normalizing Neural Networks

    Self-Normalizing Neural Networks ,长达93页的附录足以成为吸睛的地方(给人感觉很厉害), 此paper提出了新的激活函数,称之为 SELUs ,其具有normaliz ...

  2. 下载某资源文件并加载其中的所有Prefab到场景中

    using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> / ...

  3. Sql注入_类型

    1.sql注入 通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 2.sql注入类型 按照注入点类型来分类 (1)数字型注入点 在 Web ...

  4. POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】

    题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...

  5. zoj 3721 Final Exam Arrangement【贪心】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 来源:http://acm.hust.edu.cn/vjudg ...

  6. eclipse svn 分支合并到主干

    最近公司产品上线,整个系统架构包含有七八个子系统,并且子系统都是集群部署.所以每次升级维护都要确保尽可能不出问题.因为整个系统刚上线不久,意味着新系统不定期有BUG需修复,但新功能模块也在持续的开发中 ...

  7. Redis QPS测试

    1.计算qps: 1)redis发布版本中自带了redis-benchmark性能测试工具,可以使用它计算qps.示例:使用50个并发连接,发出100000个请求,每个请求的数据为2kb,测试host ...

  8. Yii2 如何更好的在页面注入CSS

    首先 先添加一个widgets,代码如下(提示:使用时注意修改命名空间) <?php /** * User: yiqing * Date: 2014/12/15 * Time: 0:21 */ ...

  9. 通过设置PHPSESSID保存到cookie实现免登录

    $cookieParams = session_get_cookie_params(); session_set_cookie_params( 3600,// 设置sessionID在cookie中保 ...

  10. 20145229吴姗珊 《Java程序设计》第6周学习总结

    20145229吴姗珊 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入\输出 1.java将输入\输出抽象化为串流,数据有来源及目的地,衔接两者的是串流对象 2.输入串 ...