Run Away

Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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).
 
 #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <algorithm>
using namespace std;
#define N 50
#define M 10
struct point
{
double x,y,mina;
};
point p[],s,tri[];
int n;
double dist(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double getmina(point tem)
{
double mina=1e9,t;
for(int i=; i<n; i++)
{
t=dist(tem,p[i]);
if(t<mina)
mina=t;
}
return mina;
}
void Simulated_Annealing()
{
int i,j;
for(i=; i<N; i++)
{
tri[i].x=((rand()%)+1.0)/1000.0*s.x;
tri[i].y=((rand()%)+1.0)/1000.0*s.y;
tri[i].mina=getmina(tri[i]);
}
double temper=s.x+s.y,dx,dy;
point tmp;
while(temper>0.001)
{
for(i=; i<N; i++)
{
for(j=; j<M; j++)
{
dx=((rand()%)+1.0)/1000.0*temper;
dy=sqrt(temper*temper-dx*dx);
if (rand()&) dx*=-;
if (rand()&) dy*=-;
tmp.x=tri[i].x+dx;
tmp.y=tri[i].y+dy;
if (tmp.x>= && tmp.x<=s.x && tmp.y>= && tmp.y<=s.y)
{
tmp.mina=getmina(tmp);
if(tmp.mina>tri[i].mina)
{
tri[i]=tmp;
}
}
}
}
temper*=0.6;
}
int mini=;
for(i=;i<N;i++)
if(tri[mini].mina<tri[i].mina)
mini=i;
printf("The safest point is (%.1lf, %.1lf).\n",tri[mini].x,tri[mini].y);
}
int main()
{
srand((unsigned int)(time(NULL)));
int t,i;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%d",&s.x,&s.y,&n);
for(i=; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
Simulated_Annealing();
}
}

Run Away 模拟退火的更多相关文章

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

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

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

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

  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. POJ 1379 Run Away 【基础模拟退火】

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

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

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

  8. 【模拟退火】poj1379 Run Away

    题意:平面上找一个点,使得其到给定的n个点的距离的最小值最大. 模拟退火看这篇:http://www.cnblogs.com/autsky-jadek/p/7524208.html 这题稍有不同之处仅 ...

  9. hdu3932 模拟退火

    模拟退火绝对是从OI--ACM以来接触过的所有算法里面最黑科技的orz 题意:地上有一堆hole,要找一个点,使得(距离该点最远的hole的距离)最小. sol:本来想套昨天的模拟退火模板,初值(0, ...

随机推荐

  1. web安全普及:通俗易懂,如何让网站变得更安全?以实例来讲述网站入侵原理及防护。

    本篇以我自己的网站[http://www.1996v.com]为例来通俗易懂的讲述如何防止网站被入侵,如何让网站更安全. 要想足够安全,首先得知道其中的道理. 本文例子通俗易懂,从"破解网站 ...

  2. postman 第4节 切换环境和设置读取变量(转)

    postman提供了environment管理功能,想要在多个环境中测试,比如在测试环境.灰度环境.生产环境等,只需要用同样的接口,切换下环境即可,非常方便.具体步骤: 切换环境 1.点击界面右上角的 ...

  3. 带你走进SAP项目实施过程——立项(1)

    到底谁会首先有上ERP的想法,可能是企业老板,也可能是总经理级别等高管.但不管是谁,在确定之前,按道理企业风控部.总经办或者信息部等相关部门都需要对ERP项目做立项申请.毕竟ERP项目涉及企业方方面面 ...

  4. ORACLE分区表、分区索引详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt160 ORACLE分区表.分区索引ORACLE对于分区表方式其实就是将表分段 ...

  5. Java异常的性能分析

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt276 在Java中抛异常的性能是非常差的.通常来说,抛一个异常大概会消耗10 ...

  6. oracle锁表问题解决方法

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp52 Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程 ...

  7. 通过编译lambda表达式来创建实例(可在反射时候用,效率比反射高一些)

    原文地址:https://rogerjohansson.blog/2008/02/28/linq-expressions-creating-objects/ 据说编译lambda创建实例是比反射快.实 ...

  8. poj1236强连通缩点

    题意:给出每个学校的list 代表该学校能链接的其他学校,问1:至少给几个学校资源使所有学校都得到:2:至少加多少个边能让所有学校相互连通: 思路:1:找出缩点后入度为零的点个数  2:找出缩点后入度 ...

  9. macOS上的ODBC-利用unixODBC连接PostgreSQL与SQLite并进行数据迁移

    安装UnixODBC & PSQLODBC driver for UnixODBC $ brew install psqlodbc Updating Homebrew... ==> In ...

  10. 个人作业2——英语学习APP案例分析(必应词典的使用)

    第一部分 调研, 评测 1.使用环境:window 10 词典版本: 2.使用体验: 打开词典出现下面这一界面: 词典模块:出现了每日一词,每日一句,每日阅读板块,还提供了生词本,个人觉得最喜欢的是这 ...