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. JS中的数据类型小结

    首先说说JS数据类型的分类.分为标准型和typeof类型(即控制台打印,浏览器区分) 标准型:基本类型中有:number.string.boolean.undefined.null  复合类型:obj ...

  2. Tomcat迁移到WebsphereURL获取中文参数乱码问题

    URL携带中文参数时,tomcat通常用两种方法可以解决中文乱码问题: String param = new String(request.getParameter("param " ...

  3. 通过日期在js中求出判断间隔天数,周期等实现分享

    在我们在项目的时候,可能出现这样的一种情况,有一个开始时间和一个结束时间,而这两个时间用$('#StartTime').val(); 取出来的时候又是datetime 类型,我们需要求这个时间中的间隔 ...

  4. 【ASP.NET MVC】View与Controller之间传递数据

    1   概述 本篇文章主要从操作上简要分析Controller<=>View之间相互传值,关于页面之间传值,如果感兴趣,可参考我另外一篇文章ASP.NET 页面之间传值的几种方式 . Co ...

  5. JS源生代码“增删改查”之增

    51呢最近在做一个管理数据的,第一次接触到用JS的源代码去实现一些功能,才知道网页里的许多功能都是依赖于“增删改查”完成的,下面的几张图片就是对于增的演示: 下面是有关HTML的代码:这个主要是弹窗部 ...

  6. C# 实现AOP 的几种常见方式

    AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的中统一处理业务逻辑的一种技术,比较常见的场景是:日志记录,错误捕获 ...

  7. javascript中用setAttribute给元素添加colspan属性无效

    先附上代码 var tr=document.createElement('TR'); var td=document.createElement('TD'); td.setAttribute('col ...

  8. [置顶] 基于FPGA的VGA简易显存设计&NIOS ii软核接入

    项目简介 本项目基于Altera公司的Cyclone IV型芯片,利用NIOS II软核,2-port RAM与时序控制模块,实现64*48分辨率的显存(再大的显存板载资源m9k不够用) 实现效果如下 ...

  9. NFA的实现

    此次发表的是一个不确定的自动机(NFA),它可以根据输入的正规式输出由函数映像表示的结果. 此版本可以输入括号'(',')',但是,实现的过程理解起来有点吃力,所以,在时间允许的情况下,我还将写新文章 ...

  10. 201521123069 《Java程序设计》 第2周学习总结

    1. 本章学习总结 (1)String类.StringBuilder类(频繁进行字符串的修改应选用StringBuilder,不会生成大量的字符串对象).Math类的用法.字符串池的概念 (2)Sca ...