传送门:http://poj.org/problem?id=1379

【题解】

题目大意:求(0,0)->(X,Y)内的一个点,使得这个点到给定的n个点的最小距离最大。

模拟退火

一开始可以先把4个顶点加入。

调调参就过样例了。

然后就过了

# include <math.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + ;
const int mod = 1e9+;
const double pi = acos(-1.0); # define RG register
# define ST static double X, Y;
int n;
struct pa {
double x, y;
double dis;
pa() {}
pa(double x, double y, double dis) : x(x), y(y), dis(dis) {}
}a[M]; namespace SA {
const double eps = 1e-, DEC = 0.9, ACCEPT_DEC = 0.5;
const int N = , T = , RAD = ;
inline double rand01() {
return rand() % (RAD + ) / (1.0 * RAD);
}
inline double getdist(double x, double y) {
double ret = 1e18;
for (int i=; i<=n; ++i)
ret = min(ret, (x-a[i].x)*(x-a[i].x)+(y-a[i].y)*(y-a[i].y));
return ret;
}
inline pa randpoint(double px, double py, double qx, double qy) {
double x = (qx - px) * rand01() + px, y = (qy - py) * rand01() + py;
return pa(x, y, getdist(x, y));
}
pa res[N + ];
inline pa main() {
res[] = pa(, , getdist(, ));
res[] = pa(X, , getdist(X, ));
res[] = pa(, Y, getdist(, Y));
res[] = pa(X, Y, getdist(X, Y));
for (int i=; i<=N; ++i) {
double x = rand01() * X;
double y = rand01() * Y;
res[i] = pa(x, y, getdist(x, y));
}
double temper = max(X, Y), accept = 0.6;
while(temper > eps) {
for (int i=; i<=N; ++i) {
for (int j=; j<=T; ++j) {
pa t = randpoint(max(res[i].x - temper, 0.0), max(res[i].y - temper, 0.0), min(res[i].x + temper, X), min(res[i].y + temper, Y));
if( <= t.x && t.x <= X && <= t.y && t.y <= Y) {
if(t.dis > res[i].dis) res[i] = t;
else if(rand01() <= accept) res[i] = t;
}
}
}
temper *= DEC;
accept *= ACCEPT_DEC;
}
pa ans;
ans.dis = ;
for (int i=; i<=N; ++i)
if(res[i].dis > ans.dis) ans = res[i];
return ans;
}
} int main() {
srand();
int T; cin >> T;
while(T--) {
cin >> X >> Y >> n;
for (int i=; i<=n; ++i) scanf("%lf%lf", &a[i].x, &a[i].y);
pa ans = SA::main();
printf("The safest point is (%.1f, %.1f).\n", ans.x, ans.y);
} return ;
}

poj1379 Run Away的更多相关文章

  1. 【模拟退火】poj1379 Run Away

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

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

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

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

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

  4. POJ1379:Run Away

    我对模拟退火的理解:https://www.cnblogs.com/AKMer/p/9580982.html 我对爬山的理解:https://www.cnblogs.com/AKMer/p/95552 ...

  5. can't run roscore 并且 sudo 指令返回 unable to resolve host

    I'm using ubuntu14 LTS. Problems: 1. When run roscore, got a mistake and an advice to ping the local ...

  6. DotNet Run 命令介绍

    前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...

  7. 布里斯班Twilight Bay Run半程马拉松

    自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...

  8. SVN:Previous operation has not finished; run 'cleanup' if it was interrupted

    异常处理汇总-开发工具  http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following ...

  9. linux 环境下运行STS时 出现must be available in order to run STS

    linux 环境下运行ECLIPSE时 出现 “ A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be avai ...

随机推荐

  1. jackson 处理空值

    @JsonInclude(value=Include.NON_NULL) public class ResultBean 这样在返回数据的时候, { "code": "s ...

  2. beanshell引用参数化数据

    步骤: 1.添加参数化组件CSV Data Set  Config: 2.添加beanshell preprocessor,引用变量: 验证: 2个线程,迭代2次,分别取了4个不同的值.

  3. MySQL☞聚合函数/分组函数

    分组函数(聚合函数) 1.count(*/列名): a.*:求出该数据的总条数 select  count(*)  from 表名 b.列名:求出该列中列名不为null的总条数 select  cou ...

  4. 第二篇 Fiddler配置_浏览器&手机

    什么是Fiddler? 网络项目的开发和测试中,Fiddler是强大的抓包工具,它的原理是以web代理服务器的形式进行工作的 ,可以说是非常常用的手头工具了,本文就Fiddler使用和配置进行说明. ...

  5. 解决EasyUI DataGrid删除行失败的方法

    笔者最近在做一个项目的后台,用到了EasyUI的datagrid控件,并开启了行内编辑功能,实际上也就是使用了edatagird这个空间,引用了edatagrid.js,一切似乎都做的顺风顺水,添加数 ...

  6. 容器基础(三): 使用Cgroups进行资源限制

    Linux Cgroups Linux Cgroups 是 Linux 内核中用来为进程设置资源限制的一个重要功能. Cgroups将进程进行分组, 然后对这一组进程进行统一的资源监控和限制.Cgro ...

  7. day-9 sklearn库和python自带库实现最近邻KNN算法

    K最近邻(k-Nearest Neighbor,KNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一.该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的 ...

  8. 判断python字典中key是否存在的两种方法

    今天来说一下如何判断字典中是否存在某个key,一般有两种通用做法,下面为大家来分别讲解一下: 第一种方法:使用自带函数实现. 在python的字典的属性方法里面有一个has_key()方法,这个方法使 ...

  9. javascript实现自动切换焦点功能学习

    当用户在表单中填写完当前字段后,能否自动将焦点跳转到下一个字段以方便用户输入? 为了增强易用性,加快数据输入的速度,可以在前一个文本框中的字符达到一定的设置的字符长度后(比如电话号码,身份证号等),用 ...

  10. Android Studio的初体验

    在机缘巧合之下遇到了安卓开发,接触了Android Studio开始了漫长的改bug的道路,以下为简易版心酸历程 首先我需要成功安装Android Studio,由于我过于叛逆以及为了避免出错于是从一 ...