poj1379 Run Away
传送门: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的更多相关文章
- 【模拟退火】poj1379 Run Away
题意:平面上找一个点,使得其到给定的n个点的距离的最小值最大. 模拟退火看这篇:http://www.cnblogs.com/autsky-jadek/p/7524208.html 这题稍有不同之处仅 ...
- poj-1379 Run Away(模拟退火算法)
题目链接: Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7982 Accepted: 2391 De ...
- 模拟退火算法(run away poj1379)
http://poj.org/problem?id=1379 Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: ...
- POJ1379:Run Away
我对模拟退火的理解:https://www.cnblogs.com/AKMer/p/9580982.html 我对爬山的理解:https://www.cnblogs.com/AKMer/p/95552 ...
- 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 ...
- DotNet Run 命令介绍
前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...
- 布里斯班Twilight Bay Run半程马拉松
自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...
- 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 ...
- 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 ...
随机推荐
- laravel+vue结合使用
SegmentFault 首页 问答 专栏 讲堂 圈子 发现 搜索 立即登录免费注册 在 SegmentFault,学习技能.解决问题 每个月,我们帮助 1000 万的开发者解决各种各样的技术 ...
- java_hdfs之读写文件
package hdfsTest.answer.hdfs; import java.io.IOException; import java.net.URI; //import java.net.URL ...
- 在Android上,怎样与Kotlin一起使用Retrofit(KAD21)
作者:Antonio Leiva 时间:Apr 18, 2017 原文链接:https://antonioleiva.com/retrofit-android-kotlin/ 这是又一个例子,关于怎样 ...
- python第三天(dictionary应用)转
1.题目: python实现英文文章中出现单词频率的统计 前言: 这道题在实际应用场景中使用比较广泛,比如统计历年来四六级考试中出现的高频词汇,记得李笑来就利用他的编程技能出版过一本背单词的畅销书 ...
- 第一周 Introduction
欢迎 欢迎来到这门关于机器学习的免费网络课程,机器学习是近年来最激动人心的技术之一,在这门课中,你不仅可以了解机器学习的原理,更有机会进行实践操作,并且亲自运用所学的算法. 每天你都可能在不知不觉中使 ...
- MongoDB的复制一:复制的原理
1.复制的角色 复制有三种角色: primay:主库,执行所有的写操作,并把日志写入oplog里. secondary:复制主库的所有操作.读取主库的oplog,并执行日志里的内容.默认情况下,客户端 ...
- java线程(7)——阻塞队列BlockingQueue
回顾: 阻塞队列,英文名叫BlockingQueue.首先他是一种队列,联系之前Java基础--集合中介绍的Queue与Collection,我们就很容易开始今天的阻塞队列的学习了.来看一下他们的接口 ...
- 搭建Elasticsearch 5.4分布式集群
多机集群中的节点可以分为master nodes和data nodes,在配置文件中使用Zen发现(Zen discovery)机制来管理不同节点.Zen发现是ES自带的默认发现机制,使用多播发现其它 ...
- qemu的drive参数解释
drive参数很简单,可以理解成是定义了一个实际的硬盘(或者是cd)与drive对应的是device-drive option[,option[,option[,...]]] Define a new ...
- JQuery事件对象的属性和方法
这是今天的总结,以后学习自己可以当参考书来读读.Event 对象代表事件的状态,比如事件在其中发生的元素.键盘按键的状态.鼠标的位置.鼠标按钮的状态.事件通常与函数结合使用,函数不会在事件发生前被执行 ...