RPFS(RP First Search) 模拟退火算法 未完
来源:互联网 发布:淘宝卖aj的正品店 编辑:程序博客网 时间:2024/06/11 23:47
POJ 2420
求费马点
代码来自网络
#include<cmath>#include<cstdio>const double inf=1e9;const int N=100;const double threshold=1e-7,delta=0.98,inital_temperature=100;const double d[4][2]={{0,1},{1,0},{0,-1},{-1,0}};int n;struct Point {double x,y;};Point p[N];inline double sqr(const double x) {return x*x;}inline double dist(const Point a,const Point b) {return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}inline double getsum(const Point x) {double ret=0;for(int i=0;i<n;i++) {ret+=dist(x,p[i]);}return ret;}int main() {scanf("%d",&n);for(int i=0;i<n;i++) {scanf("%lf%lf",&p[i].x,&p[i].y);}Point nowp=p[0];double ans=getsum(nowp),t=inital_temperature;while(t>threshold) {bool finished=false;while(!finished) {finished=true;for(int i=0;i<4;i++) {Point nextp;nextp.x=nowp.x+d[i][0]*t;nextp.y=nowp.y+d[i][1]*t;if(getsum(nextp)<ans) {ans=getsum(nextp);nowp=nextp;finished=false;}}}t*=delta;}printf("%.f\n",ans);}
阅读全文
0 1
- RPFS(RP First Search) 模拟退火算法 未完
- 模拟退火算法
- 模拟退火算法
- 模拟退火算法
- 模拟退火,遗传算法
- 模拟退火算法概述
- 模拟退火算法
- 遗传模拟退火算法
- 模拟退火遗传算法
- 模拟退火算法
- 模拟退火算法
- 模拟退火算法
- 解析模拟退火算法
- 模拟退火算法
- 模拟退火算法
- 模拟退火算法
- 模拟退火算法
- 模拟退火算法
- Python入门——数据类型
- 使用QT来绘制MAT
- C++11的强类型枚举
- 3Sum Closest
- Fileshopping
- RPFS(RP First Search) 模拟退火算法 未完
- easyui datagrid 添加操作列时设计到rowdata传参问题
- Wannafly 牛客网 挑战赛2 A
- PullToRefreshListView
- 【bzoj 2044】三维导弹拦截(网络流)(拓扑排序)
- Sklearn-train_test_split随机划分训练集和测试集
- leetcode 25. Reverse Nodes in k-Group
- ReactNative——动画学习
- Android 利用WindowManager实现悬浮窗