题目:http://poj.org/problem?id=2420

精度设成1e-17,做三遍。ans设成double,最后再取整。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<ctime>
#define db double
using namespace std;
const int N=;
const db dc=0.99,eps=1e-;
int n,nx[N],ny[N];
db px,py,ans;
db dis(db x0,db y0,db x1,db y1)
{
return sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
db calc(db x,db y)
{
db ret=;
for(int i=;i<=n;i++)ret+=dis(nx[i],ny[i],x,y);
return ret;
}
db gtrd(db T){return (rand()*-RAND_MAX)*T;}
void SA(db T)
{
db x0=px,y0=py,pr=calc(x0,y0),x,y,cr;
while(T>eps)
{
x=x0+gtrd(T); y=y0+gtrd(T); cr=calc(x,y);
if(cr<pr||(exp((cr-pr)/T)*RAND_MAX<rand()))
{
ans=min(ans,cr);
x0=x;y0=y;pr=cr;
}
T*=dc;
}
}
int main()
{
srand(time());
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&nx[i],&ny[i]),px+=nx[i],py+=ny[i];
px/=n; py/=n; ans=calc(px,py);
SA();SA();SA();
printf("%.0lf\n",ans);
return ;
}

poj 2420 A Star not a Tree?——模拟退火的更多相关文章

  1. poj 2420 A Star not a Tree? —— 模拟退火

    题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...

  2. POJ 2420 A Star not a Tree?(模拟退火)

    题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...

  3. 三分 POJ 2420 A Star not a Tree?

    题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...

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

  7. POJ 2420 A Star not a Tree?【爬山法】

    题目大意:在二维平面上找出一个点,使它到所有给定点的距离和最小,距离定义为欧氏距离,求这个最小的距离和是多少(结果需要四舍五入)? 思路:如果不能加点,问所有点距离和的最小值那就是经典的MST,如果只 ...

  8. 【POJ】2420 A Star not a Tree?(模拟退火)

    题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ...

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

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

随机推荐

  1. Redis专题(2):Redis数据结构底层探秘

    前言 上篇文章Redis闲谈(1):构建知识图谱介绍了redis的基本概念.优缺点以及它的内存淘汰机制,相信大家对redis有了初步的认识.互联网的很多应用场景都有着Redis的身影,它能做的事情远远 ...

  2. python升级安装后的yum的修复

    升级python版本号后,执行yum # yum -y install openssl 提演示样例如以下: There was a problem importing one of the Pytho ...

  3. 时间控件(DateTime Picker)

    中文:http://www.bootcss.com/p/bootstrap-datetimepicker/index.htm http://www.malot.fr/bootstrap-datetim ...

  4. php nginx超时出错

    执行PHP操作大文件insert mysql数据库时,出现这个错误提示 The page you are looking for is temporarily unavailable.Please t ...

  5. 如何将linux服务器作为文件服务器

    在开发过程中想要使用linux服务器作为文件服务器,可以通过 IP+文件名来获取文件信息,比如http://localhost/banner/a.jpg.设置过程如下 1.安装apache2 sudo ...

  6. 箭头函数 this arrow function 无this

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions import w ...

  7. An Overview of Query Optimization in Relational Systems

    An Overview of Query Optimization in Relational Systems

  8. Linux入门基础(一)——ls、mkdir命令

  9. angularJs-未加载完成的页面显示混乱ng-bind

    ng-bind 未初始化完成不加载数据,避免产生{{}}导致页面混乱 还是上边的例子,当前页面没有加载完成的时候,页面显示是不完整的会频繁的出现{{}}这样子的表达式语句,给用户的感觉很不和谐,所以使 ...

  10. HTML——input

    一个简单的HTML表单,包含两个文本输出框和一个提交按钮: <form action="form_action.asp" method="get"> ...