pojA Star not a Tree?
题目链接
题解
啊,模拟退火是个好东西
模拟退火即可
代码
#include<cmath>
#include<cstdio>
#include<algorithm>
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9')c = getchar();
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
#define INF 1e18
#define eps 1e-10
int n;
struct Node {
double x,y;
} p[101];
double dis(Node a,Node b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double calc(Node a) {
double sum = 0;
for(int i = 1;i <= n;++ i)
sum += dis(a,p[i]);
return sum;
}
#define T 100
#define delta 0.98
double Rand() {
return (double) rand() / (double)RAND_MAX;
}
#define IT 5
double dx[7] = {1,0,-1,0,1};
double solve() {
Node x = p[1];
double res = calc(x);
double t = T;
while(t > eps) {
for(int i = 1;i < IT; ++ i) {
for(int i = 0;i <= 4;++ i) {
Node nx = x;
nx.x += dx[i] * Rand() * t;
nx.y += dx[i + 1] * Rand() * t;
double nxres = calc(nx);
if(nxres < res || Rand() >= exp((nxres - res) / res)) res = nxres,x = nx;
}
}
t *= delta;
}
return res;
}
int main() {
srand(20010901);
n = read();
for(int i = 1;i <= n;++ i)
scanf("%lf%lf",&p[i].x,&p[i].y);
double ans = INF;
for(int i = 1;i <= 10;++ i) {
ans = std:: min(ans,solve());
}
printf("%.0lf\n",ans);
}
pojA Star not a Tree?的更多相关文章
- POJA Star not a Tree?(模拟退火)
题意 题目链接 给出$n$个点,求出一个点使得到各个点的距离之和最小,距离为欧几里得距离 Sol 模拟退火真是玄学,我退了一上午,最后把exp函数去了就A了. 后来改了改,发现是大小符号的问题.. 但 ...
- POJ 2420:A Star not a Tree?
原文链接:https://www.dreamwings.cn/poj2420/2838.html A Star not a Tree? Time Limit: 1000MS Memory Limi ...
- POJ 2420 A Star not a Tree? 爬山算法
B - A Star not a Tree? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...
- [POJ 2420] A Star not a Tree?
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ...
- POJ 2420 A Star not a Tree? (计算几何-费马点)
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3435 Accepted: 172 ...
- uva 10228 - Star not a Tree?(模拟退火)
题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...
- 模拟退火算法A Star not a Tree?(poj2420)
http://write.blog.csdn.net/postedit A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Tot ...
- poj2420 A Star not a Tree? 找费马点 模拟退火
题目传送门 题目大意: 给出100个二维平面上的点,让你找到一个新的点,使这个点到其他所有点的距离总和最小. 思路: 模拟退火模板题,我也不懂为什么,而且一个很有意思的点,就是初始点如果是按照我的代码 ...
- poj-2420 A Star not a Tree?(模拟退火算法)
题目链接: A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5219 Accepte ...
随机推荐
- Linux RPM、YUM、APT包管理工具
⒈rpm包的管理 1)介绍 rpm是一种用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中,它生成具有.RPM扩展名的文件,RPM是RedHat Package Manager(RedH ...
- mysqlbinlog恢复数据注意事项【转】
mysqlbinlog 恢复数据注意事项 前言: 上次有个有个朋友恢复 MySQL 数据,一直恢复不成功,也没有报错信息,使用的环境是 MySQL 5.7 使用了 GTID 以及 binlog 格式为 ...
- chattr的使用
让某个文件只能往里面追加内容,不能删除,一些日志文件适用于这种操作: chattr +a /home/caolei/.bash_history 查看lsattr /home/caolei/.bash_ ...
- ES系列十八、FileBeat发送日志到logstash、ES、多个output过滤配置
一.FileBeat基本概念 简单概述 最近在了解ELK做日志采集相关的内容,这篇文章主要讲解通过filebeat来实现日志的收集.日志采集的工具有很多种,如fluentd, flume, logst ...
- mysql系列五、mysql中having的用法
HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 和 SELECT 的交互方式类似.WHERE 搜索条件在进行分组操作之前应用:而HAVING 搜索条件在进行分组操作之后应用. ...
- http响应头设置
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletExcep ...
- java.lang.NoClassDefFoundError: com/google/inject/Injector
报错如下: 解决方案: <dependency> <groupId>com.google.inject</groupId> <artifactId>gu ...
- 下载文件的一致性验证之MD5值校验
前几天写脚本遇到下载功能校验,一时间不到怎么校验好? 于是请教大神,大神给出方案如下: 先去了解一下你们的产品针对这个下载功能有没有做什么功能设计...然后再针对这些功能设计去设计测试用例...比如 ...
- java.net.ServerSocket 解析
注:本文来自:简书:jianshu 作者:jijs链接:http://www.jianshu.com/p/7c0722a8b66f來源:简书著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- LeetCode(6):Z字形转换
Medium! 题目描述: 将字符串 "PAYPALISHIRING" 以Z字形排列成给定的行数:(下面这样的形状) P A H N A P L S I I G Y I R 之后按 ...