poj2420 模拟退火
来源:互联网 发布:金融数据 编辑:程序博客网 时间:2024/04/28 23:34
害怕爬山算法挂掉,所以改成了新的模拟退火
模拟退火就是在爬山算法的基础上又新增加了一个 以一定概率接受最优解。
就是一个exp 比一个随机在(0,1)的概率小,就接受。
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>#include<cmath>#include<ctime>using namespace std;const int maxn=105;int n;double xi[maxn],yi[maxn];double dis(double x,double y){double res=0;for(int i=1;i<=n;i++){res+=sqrt((xi[i]-x)*(xi[i]-x)+(yi[i]-y)*(yi[i]-y));}return res;}int main(){srand(time(NULL));while(scanf("%d",&n)!=EOF){for(int i=1;i<=n;i++)scanf("%lf%lf",&xi[i],&yi[i]);double step=100000;double x=xi[1],y=yi[1];double ans=dis(x,y);while(step>1e-10){double rad=rand()%360+1;double nx=x+step*cos(rad);double ny=y+step*sin(rad);double tmp=dis(nx,ny);if(tmp<ans){ans=tmp;x=nx;y=ny;}else{if(exp((tmp-ans)/step)<(rand()%10000)/10000.0){ans=tmp;x=nx;y=ny;}}step*=0.99;}printf("%.0f\n",ans);}return 0;}
0 0
- POJ2420模拟退火
- poj2420(模拟退火)
- poj2420 模拟退火
- POJ2420 & HDU1109 模拟退火
- [POJ2420]模拟退火
- POJ2420 费马点问题求解 随机化 模拟退火
- 【退火!!!退火!!!】poj2420
- 模拟退火算法A Star not a Tree?(poj2420)
- 【模拟退火,广义费马点】POJ2420 A Star not a Tree?
- poj2420 A Star not a Tree?【模拟退火】
- [Poj2420]A Star not a Tree? (爬山算法||模拟退火算法)
- 模拟退火
- 模拟退火
- 模拟退火
- 模拟退火
- 模拟退火
- 模拟退火
- 模拟退火
- 欢迎使用CSDN-markdown编辑器
- Android中ListView.getCount()与ListView.getChildCount()区别
- C++: 高精度加法与高精度减法
- React Native学习之RCTDeviceEventEmitter(类似iOS的NSNotificationCenter)简单用法以及背景透明
- C内存分配方式与C++内存分配方式
- poj2420 模拟退火
- action 提示框
- 广播与服务二
- 基于ZigBee和STM32的智能家居控制系统的设计与实现(收藏)
- HTML5新增结构标签
- Leetcode 290. Word Pattern
- jquery如何判断滚动条滚到页面底部并执行事件
- http协议一
- [2016-3-23 Test]