题目链接:

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. [转]postman 官方文档解说

    1. 安装 两种安装方式,我热衷于以chrome插件形式安装 Chrome插件 Mac App 2. 发送请求 Postman最基础的功能就是发送http请求,支持GET/PUT/POST/DELET ...

  2. Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin

    前言:随着微服务系统的增加,服务之间的调用关系变得会非常复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得非常重要了.spring cloud sleuth实现了对分布式服务的监控解决 ...

  3. 【原创】Hibernate自动生成(2)

    本实战是博主初次学习Java,分析WCP源码时,学习HibernateTools部分的实战,由于初次接触,难免错误,仅供参考,希望批评指正. 开发环境: Eclipse Version: Photon ...

  4. 【BZOJ2322】[BeiJing2011]梦想封印 高斯消元求线性基+DFS+set

    [BZOJ2322][BeiJing2011]梦想封印 Description 渐渐地,Magic Land上的人们对那座岛屿上的各种现象有了深入的了解. 为了分析一种奇特的称为梦想封印(Fantas ...

  5. EasyDSS流媒体解决方案实现的实时数据统计报表、视频文件上传、点播、分享、集成代码等功能

    之前的EasyDSS作为rtmp流媒体服务器自从推出就备受用户好评,随着用户的需求的变更产品自身的发展是必须的: 为了更好的用户体验和和功能的完善,我们在EasyDSS的基础上增添了服务器硬件数据报表 ...

  6. ubuntu14.04 desktop 32-bit kvm装windows xp

    经过这几天来的折腾,总算是在ubuntu14.04用kvm装上了xp, 看不少的的贴,也绕了不少的圈,总的来说,非常感谢CSDN上的"上善若水75",看着他写的一个分类" ...

  7. 2015年11月26日 Java基础系列(七)正则表达式Regex

    package com.demo.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @autho ...

  8. android菜鸟学习笔记23----ContentProvider(三)利用内置ContentProvider监听短信及查看联系人

    要使用一个ContentProvider,必须要知道的是它所能匹配的Uri及其数据存储的表的结构. 首先想办法找到访问短信及联系人数据的ContentProvider能接受的Uri: 到github上 ...

  9. csv文件的格式

    csv, comma separated values csv是一种纯文本文件. csv文件由任意数目的记录构成,记录间以换行符分割,每条记录由字段构成,字段间以逗号作为分隔符. 如果字段中有逗号,那 ...

  10. Django 之 缓存机制

    Django 缓存机制 缓存介绍 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的用户访问量很大的时候,每一次 ...