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

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). 思路:直接按照题解做的,首先列举30个随机点,然后分别进行短距离的随机尝试
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
const double Pi=acos(-1.0);
const double eps=1e-3;
const double inf=1e20;
double px[31],py[31],d[31],x[1111],y[1111];
double caldis(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
int T;
scanf("%d",&T);
srand(9876543);
while(T--){
int a,b,m;
scanf("%d%d%d",&a,&b,&m);
for(int i=0;i<m;i++){
scanf("%lf%lf",x+i,y+i);
}
for(int i=0;i<30;i++){
px[i]=(double)(rand()%1000+1)/1000.000*a;
py[i]=(double)(rand()%1000+1)/1000.000*b;
d[i]=inf;
for(int j=0;j<m;j++)d[i]=min(d[i],caldis(px[i],py[i],x[j],y[j]));
}
double delta=double(max(a,b))/(sqrt(1.0*m));
while(delta>eps){
for(int i=0;i<30;i++){
double tx=px[i],ty=py[i];
for(int j=0;j<30;j++){
double theta=(double)(rand()%1000+1)/1000.000*10*Pi;
double dx=delta*cos(theta);
double dy=delta*sin(theta);
tx+=dx;ty+=dy;
if(tx<0||tx>a||ty<0||ty>b){tx-=dx;ty-=dy;continue;}
double td=inf;
for(int k=0;k<m;k++)td=min(td,caldis(tx,ty,x[k],y[k]));
if(td>d[i]){
d[i]=td;px[i]=tx;py[i]=ty;
}
tx-=dx;ty-=dy;
}
}
delta*=0.9;
}
double ans=0;int ind=0;
for(int i=0;i<30;i++){
if(d[i]>ans){
ind=i;
ans=d[i];
}
}
printf("The safest point is (%.1f, %.1f).\n",px[ind],py[ind]);
}
return 0;
}

  

poj 1379 Run Away 模拟退火 难度:1的更多相关文章

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

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

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

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

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

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

  4. POJ 1379 Run Away

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

  5. POJ 1379 模拟退火

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

  6. POJ 1379 (随机算法)模拟退火

    题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...

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

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

  8. 【BZOJ1844/2210】Pku1379 Run Away 模拟退火

    [BZOJ1844/2210]Pku1379 Run Away 题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大. 题解:模拟退火的裸题,再调调调调调参就行了~ #inclu ...

  9. poj 2069 Super Star —— 模拟退火

    题目:http://poj.org/problem?id=2069 仍是随机地模拟退火,然而却WA了: 看看网上的题解,都是另一种做法——向距离最远的点靠近: 于是也改成那样,竟然真的A了...感觉这 ...

随机推荐

  1. windows下mysql安装失败的一个解决案例

    操作系统:windows8.1,之前安装过mysql,这次安装在配置的最后一部执行“Apply security settings”的过程中弹出经典错误: Access denied for user ...

  2. 【Python】__slots__ 、@property、多重继承、定制类、枚举类、元类

    __slots__ @property 多重继承 定制类 枚举类 元类 [使用__slots__] 1.动态语言的一个特点就是允许给实例绑定任意的方法和变量,而静态语言(例如Java)必须事先将属性方 ...

  3. Python面试题之Python反射机制

    0x00 前言 def f1(): print('f1') def f2(): print('f2') def f3(): print('f3') def f4(): print('f4') a = ...

  4. JAVA面试题整理(1)-基础

    1.List 和 Set 的区别  共同点:它们都是Collection的子接口 区别: List:这个接口能够精准的记录每一个元素的插入位置(换句话说就是这个接口内容所有元素是按照顺序去保存的),使 ...

  5. mapper的namespace

    一般情况下mapper的namespace能随便写,不重复即可, 但如果希望使用mybatis动态代理的接口,就需要namespace中的值和需要对应的Mapper(dao)接口的全路径一致.例如:c ...

  6. SVN添加忽略目录

    项目:Thinkphp 目录结构: Thinkphp |-- Common |-- Runtime |-- Home 忽略目标: Runtime 文件夹及下面所有文件 首先,需要忽略的目录必须没有加入 ...

  7. excel省市区三级分类级联

    前言:同事正好需要一个这样的地址类型给用户使用下载模板,改好地址再导入,这样就不会出现地址不匹配问题.所以就自己也整理了一套,以备不时之需. 效果展示: 图一:省级 图二:市级 图三:区级 图四:各乡 ...

  8. 获取用户真实IP,php实现

    function get_client_ip() { if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv(" ...

  9. Java循环语句之 while

    生活中,有些时候为了完成任务,需要重复的进行某些动作.如参加 10000 米长跑,需要绕 400 米的赛道反复的跑 25 圈.在 Java 中实现功能时,也经常需要重复执行某些代码,例如,我们为了表示 ...

  10. ItemsControl的ItemContainerStyle属性

    ItemsControl:ListBox,ComboBox,TreeView ItemContainerStyle是用来设置每一个集合控件的Item的样式的属性(即设置每一个项的样式).   使用It ...