设为首页 加入收藏

TOP

POJ 2420 A Star not a Tree? 费马点 计算几何 模拟退火
2015-07-20 17:39:50 来源: 作者: 【 】 浏览:2
Tags:POJ 2420 Star not Tree 费马点 计算 几何 模拟

题目大意:给出平面中一些点,求平面中的一个点,使得这个点到其他所有点的距离之和最短,并输出这个距离和。


思路:模拟退火。精度到整数。。。没什么需要注意的。。

话说费马点只能用模拟退火求近似解吧


CODE:


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #define MAX 510 #define INF 0x7f7f7f7f #define EPS 1e-2 #define PI acos(-1.0) using namespace std; struct Point{ double x,y; double length; Point(double _x,double _y):x(_x),y(_y) {} Point() {} void Read() { scanf("%lf%lf",&x,&y); } }point[MAX],now,ans; int points; double dE; void Simulated_Annealing(); inline double Rand(); inline double Statistic(Point p); inline double Calc(Point p1,Point p2); int main() { cin >> points; for(int i = 1;i <= points; ++i) point[i].Read(); now = Point(5000.0,5000.0); min_length = Statistic(now); Simulated_Annealing(); printf("%.0f",ans.length); return 0; } void Simulated_Annealing() { double L = 10000.0; while(L > EPS) { double alpha = 2 * PI * Rand(); Point temp(now.x + cos(alpha) * T,now.y + sin(alpha) * T); dE = Statistic(now) - Statistic(temp); if(dE >= 0 || exp(dE / L) > Rand) now = temp; L *= .99; } } inline double Rand() { return (rand() % 1000.0 + 1) / 1000.0; } inline double Statistic(Point p) { double re = 0.0; for(int i = 1;i <= points; ++i) re += Calc(point[i],p); return re; } inline double Calc(Point p1,Point p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); }
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 5015 233 Matrix(构造矩阵) 下一篇hdu 5015 233 Matrix(西安网络赛..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·python数据分析岗的 (2025-12-25 10:02:21)
·python做数据分析需 (2025-12-25 10:02:19)
·成为一个优秀的pytho (2025-12-25 10:02:16)
·Java后端面试实习自 (2025-12-25 09:24:21)
·Java LTS版本有哪些 (2025-12-25 09:24:18)