传送门: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. 实用脚本 4 -- Makefile(不同文件下的多个可执行文件or静态库编译到同一目录下)

    不同文件下的多个可执行文件编译到同一目录下,这样方便观察编译结果,从而方便进程操作.使用时根据自己的需要在进行局部修改(如 链接库.目标文件等等). 1..bashrc 中设置编译主目录(例如) ex ...

  2. 【数据结构】 List 简单实现

    public class XList<T> : IEnumerable, IEnumerator { #region List 简单实现 /// <summary> /// 存 ...

  3. Django笔记 —— Admin(Django站点管理界面)

    最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...

  4. 在PXC中重新添加掉线节点

      Preface       When we add a new node into PXC structure,it will estimate the mothed(IST/SST) to tr ...

  5. 【个人训练】(POJ1276)Cash Machine

    最近的很多题解应该都是dp相关的了,emmm因为dp对我而言思考难度比较大,那么为了理顺自己的思路当然只能通过写blog整理了.愿我能成功搞定dp这个大关!(至少中等难度的dp要能够解决啊o(TヘTo ...

  6. 第九篇 Python数据类型之集合

    集合 set 写在最前,必须要会的:1.长度len2.成员运算in和not in3.|合集4.&交集5.-差集6.^对称差集7.==8.父集:>,>= 9.子集:<,< ...

  7. [OpenCV]DMatch类和KeyPoints类:特征点匹配

    DMatch struct CV_EXPORTS_W_SIMPLE DMatch { CV_WRAP DMatch() : queryIdx(-), trainIdx(-), imgIdx(-), d ...

  8. 今日头条 2018 AI Camp 视频面试

    1. 本次面试是在牛客网平台进行的,没有涉及到技术细节,面试官也说仅仅是聊天.但是,不知道是网络卡顿还是平台缘故,连接非常不稳定,经常听不到声音,对方那边噪音也特别大,面试体验不是很好. 2. 面试时 ...

  9. K-Means和FCM聚类

    K均值聚类是基于原型的.划分的聚类方法.聚类数K由用户指定,初始的K个聚类中心随机选取,然后将每个点分派到最近的聚类中心,形成K个簇,接下来重新计算每个簇的聚类中心,重复上一步,直到簇不发生变化或达到 ...

  10. 复合类型的声明——是int *p还是int* p

    我们先来看一条基本类型的声明语句:int a, b, ... 即一条声明语句由一个数据类型(int)和紧随其后的一个变量名列表(a, b, ...)组成 更通用的描述是:一个基本数据类型和紧随其后的一 ...