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 ...
随机推荐
- MySQL高可用之PXC安装部署
Preface Today,I'm gonna implement a PXC,Let's see the procedure. Framework Hostname IP P ...
- 基于Python的接口自动化-01
为什么要做接口测试 当前互联网产品迭代速度越来越快,由之前的2-3个月到个把月,再到班车制,甚至更短,每次发版之前都需要对所有功能进行回归测试,在人力资源有限的情况下,做自动化测试很有必要.由于UI更 ...
- selenium 的安装使用
直接pip安装 pip install selenium 默认是火狐浏览器,需要安装下面网址的软件,解压后加入到环境变量中就可以了 https://github.com/mozilla/geckodr ...
- 实现网页布局的自适应 利用@media screen
利用@media screen实现网页布局的自适应,IE9一下不支持 @media screen /*1280分辨率以上(大于1200px)*/ @media screen and (min-widt ...
- DFS(2)——hdu1241Oil Deposits
一.题目回顾 题目链接:Oil Deposits 题意:给你一块网格,网格被分为面积相等的地块,这些地块中标记'@'的是油田,标记'*'的不是油田.已知一块油田与它上下左右以及对角线的油田同属一片油区 ...
- 玩ktap
1.ktap是否有过滤的功能,之前bpf程序可以阻止某些trace的log的输出,ktap是否有这样的功能呢? 2.ftrace 和 perf 的ring buffer好像不是一个,有什么区别? 需求 ...
- Redis学习笔记之基础篇
Redis是一款开源的日志型key-value数据库,目前主要用作缓存服务器使用. Redis官方并没有提供windows版本的服务器,不过微软官方开发了基于Windows的Redis服务器Micro ...
- tomcat 路径"/"表示根目录
- C#的23种设计模式概括
创建型: 1. 单件模式(Singleton Pattern) 2. 抽象工厂(Abstract Factory) 3. 建造者模式(Builder) ...
- DataBase -- Second Highest Salary
Question: Write a SQL query to get the second highest salary from the Employee table. +----+-------- ...