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. MyBatis框架知识整理

    MyBatis框架 一.介绍: MyBatis实际上是Ibatis3.0版本以后的持久化层框架[也就是和数据库打交道的框架]! 和数据库打交道的技术有: 原生的JDBC技术---> Spring ...

  2. 使用 qemu 搭建内核开发环境

    本文主要介绍在 MacOS 上使用 qemu 搭建 Linux Kernel 的开发环境.(在开始之前需要注意的是,本文中的 Linux 开发环境是一个远程服务器,而 qemu 被安装在本地的 Mac ...

  3. MongoDB聚合

    --------------------MongoDB聚合-------------------- 1.aggregate():     1.概念:         1.简介             ...

  4. 如何搭建Zookeeper集群

     ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的 ...

  5. Git 入门篇

    什么是Git   Git是Linux发明者Linus开发的一款新时代的版本控制系统. Git安装 Mac:https://sourceforge.net/projects/git-osx-instal ...

  6. 转载 远程用户连接mysql授权

    授权法:  在安装mysql的机器上运行:  1.d:\mysql\bin\>mysql -h localhost -u root  //这样应该可以进入MySQL服务器  2.mysql> ...

  7. java锁机制

    2.4 锁机制        临界区是指,使用同一个锁控制的同一段代码区或多段代码区之间,在同一时间内最多只能有一个线程在执行操作.这个概念与传统的临界区有略微的差别,这里不想强调这些概念上的差别,临 ...

  8. locale命令设置语言环境

    locale命令设置语言环境 在Linux中通过locale来设置程序运行的不同语言环境,locale由 ANSI C提供支持.locale的命名规则为_.,如zh_CN.GBK,zh代表中文, CN ...

  9. 201521123033《Java程序设计》第12周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...

  10. Java课程设计 ————五子棋 (个人博客)

    JAVA课程设计 五子棋(博客个人版) •团队课程设计博客链接 http://www.cnblogs.com/mz201521044152/p/7065575.html •个人负责模块或任务说明 1. ...