题目链接

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?的更多相关文章

  1. POJA Star not a Tree?(模拟退火)

    题意 题目链接 给出$n$个点,求出一个点使得到各个点的距离之和最小,距离为欧几里得距离 Sol 模拟退火真是玄学,我退了一上午,最后把exp函数去了就A了. 后来改了改,发现是大小符号的问题.. 但 ...

  2. POJ 2420:A Star not a Tree?

    原文链接:https://www.dreamwings.cn/poj2420/2838.html A Star not a Tree? Time Limit: 1000MS   Memory Limi ...

  3. 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 ...

  4. [POJ 2420] A Star not a Tree?

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4058   Accepted: 200 ...

  5. POJ 2420 A Star not a Tree? (计算几何-费马点)

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3435   Accepted: 172 ...

  6. uva 10228 - Star not a Tree?(模拟退火)

    题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...

  7. 模拟退火算法A Star not a Tree?(poj2420)

    http://write.blog.csdn.net/postedit A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Tot ...

  8. poj2420 A Star not a Tree? 找费马点 模拟退火

    题目传送门 题目大意: 给出100个二维平面上的点,让你找到一个新的点,使这个点到其他所有点的距离总和最小. 思路: 模拟退火模板题,我也不懂为什么,而且一个很有意思的点,就是初始点如果是按照我的代码 ...

  9. poj-2420 A Star not a Tree?(模拟退火算法)

    题目链接: A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5219   Accepte ...

随机推荐

  1. Python中__repr__和__str__区别

    Python中__repr__和__str__区别 看下面的例子就明白了 class Test(object): def __init__(self, value='hello, world!'): ...

  2. Python3 Win下安装 scipy

    没有利用Anaconda安装python库时可能遇到一些问题,例如直接 pip3 install scipy 可能报错,安装失败.原因是Scipy的安装需要依赖MKL库,官方的Numpy不包含MKL, ...

  3. Python 优雅获取本机 IP 方法【转】

    转自:https://www.cnblogs.com/lfxiao/p/9672975.html 见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 ...

  4. linux 内核是什么?

    一:linux系统如何构成的?User space:User Applications and GNU C library (glibc)kernel space:System Call interf ...

  5. 源码编译安装nginx1.4.7

    传统上基于进程或线程模型架构的web服务通过每进程或每线程处理并发连接请求,这势必会在网络和I/O操作时产生阻塞,其另一个必然结果则是对内存或CPU的利用率低下.生成一个新的进程/线程需要事先备好其运 ...

  6. Ex 6_4 判断序列是否由合法单词组成..._第六次作业

    设字符串为s,字符串中字符的个数为n,vi[i]表示前i+1个字符是否能组成有效的单词vi[i]=true表示能组成有效的单词,vi[i]=false表示不能组成有效的单词,在每个字符串前加一个空格, ...

  7. Expm 3_2 寻找最邻近的点对

      [问题描述] 设p1=(x1,y1), p2=(x2,y2), … , pn=(xn,yn) 是平面上n个点构成的集合S,设计和实现找出集合S中距离最近点对的算法. 每一个格子最多只能存在一个点, ...

  8. Day4--------------对文件的权限管理

    一.文件权限 ls -l         显示当前文件详细信息 例: -rw-r--rwx.1 root root 1415 11月 9 20:21 anaconda-ks.cfg 依次顺序为:权限信 ...

  9. 【splunk】仪表盘导入导出

    仪表盘导出: splunk目录/etc/users/admin/search/local/data/ui/views  目录下,拷贝所有的xml文件 导入: 创建仪表盘->编辑来源   将上面导 ...

  10. hdu4812 逆元+树分治

    逆元链接:https://www.cnblogs.com/zzqc/p/7192436.html 经典的树分治题 #pragma comment("linker,"/STACK:1 ...