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 ...
随机推荐
- Dos命令%date:~0,10%
在使用命令对数据库备份的时候,想让备份的文件以当天的日期命名.需要获取当天的日期,获取当天的日期用date命令,获取当天的时间用time命令.但时间和日期一般都是有一定格式的,而使用的时候,是不想用那 ...
- Vue学习(五):列表渲染
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python接口自动化: CAS系统验证,自动完成登录并获取token,遇到302请求重定向设置(requests模块 allow_redirects=False)即可
import requestsimport re import requests import re class Crm_token(object): try: username=int(input( ...
- 再见NullPointerException。在Kotlin里null的处理(KAD 19)
作者:Antonio Leiva 时间:Apr 4, 2017 原文链接:https://antonioleiva.com/nullity-kotlin/ 关于Kotlin最重要的部分之一:无效处理, ...
- asm和file system之间数据文件的转换
How to move a datafile from a file system to ASMMoving a datafile from the file system can be achive ...
- 九度OJ--1165(C++)
#include <iostream>#include <string>#include <vector> using namespace std; int mai ...
- 容器基础(七): 使用docker compose部署程序
配置 在上一节的基础上, 增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...
- 用vs调试项目页面无样式
ASP.NET Development Server 上的文件授权 在文件系统网站中,静态文件(例如图像和样式表)遵守 ASP.NET 授权.例如,如果禁用了对静态文件的匿名访问,匿名用户则不能使用文 ...
- 自定义Json格式
老铁们都知道,一般的json格式就是键值对格式,在一些特定的框架或者系统中,会用到自定义格式的json文件,假设我们要得到的特定格式json格式如下: {"A":"2&q ...
- 安装并配置maven
1下载Maven 2添加仓库(仓库就是maven项目统一存放依赖的地方 根据groupId ArtifactId Version来组成项目依赖路径) conf——settings.xml------- ...