【POJ1379】Run Away 模拟退火
来源:互联网 发布:gpu优化工程师 编辑:程序博客网 时间:2024/05/21 05:36
#include <stdio.h>int main(){puts("转载请注明出处[vmurder]谢谢");puts("网址:blog.csdn.net/vmurder/article/details/43526827");}
题意:
给若干个点,现在求一个点,使它到离它最近的点尽量远。
题解:
我写的是模拟退火先玩一会,然后小幅度爬爬山。
种子的采用是20134858
是生日^人的名字首字母hash。
诶可算A了,看来我脸还不是太黑。
代码:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 10100#define dinf 1e18#define eps 1e-5#define down 0.998using namespace std;double n,m;struct Point // 点{double x,y,z; // 坐标、该点作为结束点的答案。Point(double _x=0.0,double _y=0.0):x(_x),y(_y){}bool in(){if(x<0.0||x>n)return 0;if(y<0.0||y>m)return 0;return 1;}}P[N],now,ans;int p;// 随机函数,随机出来一个0~1之间的小数inline double Rand(){return ((double)(rand()%1000+1.0))/1000.0;}// 其实找初始点时最好找平均数之类inline void init() {double tempx=0.0,tempy=0.0;for(int i=1;i<=p;i++)tempx+=P[i].x,tempy+=P[i].y;tempx+=2*n,tempy+=2*m;now=Point(tempx/(p+4),tempy/(p+4));//now=Point(n/2,m/2);ans.z=0.0;}// 计算两点间欧拉距离inline double calc(const Point &a,const Point &b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}// 计算所有点到点a的欧拉距离最小值并更新ansinline double Calc(Point &a){a.z=dinf;for(int i=1;i<=p;i++)a.z=min(a.z,calc(P[i],a));if(a.z>ans.z)ans=a;return a.z;}Point newpos(double T,const Point &a){double alp=2.0*acos(-1.0)*Rand(); // 角度return Point(a.x+T*cos(alp)*Rand(),a.y+T*sin(alp)*Rand());}// 模拟退火void Std_Anne() // [S]imula[t]e[d] [Anne]aling{ // 温度,或者说转移半径for(double T=sqrt(n*n+m*m)*0.42;T>eps;T*=down) // 每次降温{Point next=newpos(T,now);// next为转移后的点if(next.in()){double dis=Calc(next)-Calc(now);if(exp(dis/T)>Rand()-eps)now=next;}}}// 爬山void ioi() // Cl[i]mb M[o]unta[i]n{double T=0.5,alp;for(int i=1;i<=50000;i++){Point next=newpos(T,ans);if(next.in()){double dis=Calc(next)-Calc(now);if(dis>0)now=next;}}}int main(){freopen("test.in","r",stdin);srand(20134858);int i,j,k,g;for(scanf("%d",&g);g--;){scanf("%lf%lf%d",&n,&m,&p);for(i=1;i<=p;i++)scanf("%lf%lf",&P[i].x,&P[i].y);init();Std_Anne();ioi();printf("The safest point is (%.1lf, %.1lf).\n",ans.x,ans.y);}return 0;}
0 0
- 【模拟退火】 poj1379 Run Away
- 【POJ1379】Run Away 模拟退火
- 模拟退火算法(run away poj1379)
- 模拟退火 hdu1109 Run away
- poj1379 模拟退火
- poj1379——Run Away
- POJ--1379[Run Away] 模拟退火
- 【POJ 1379 Run Away模拟退火】
- poj 1379 Run away 模拟退火
- POJ 1379 Run Away(基础模拟退火)
- poj 1379 Run Away(模拟退火)
- [poj 1379]Run Away[模拟退火]
- POJ 1379 Run Away(模拟退火)
- poj 1379 Run Away 模拟退火
- POJ 1379 Run Away 模拟退火
- POJ 1379 run away 模拟退火算法
- HDU 1109 Run Away 模拟退火算法
- 【HDU 1109 Run Away 模拟退火算法】
- Android应用程序组件Content Provider的共享数据更新通知机制分析
- Device Tree(三):代码分析
- 在eclipse里面显示cocos CCLOG 内容方法及遇到的问题
- 海外优秀资讯抢先看11:Android的Inbox如何做到70%代码能跨Android/iOS/Web 平台的秘密武器
- Cilk所有内容、资料
- 【POJ1379】Run Away 模拟退火
- 央行降准 A股牛市再加码?
- unity 学习 做的例子截图
- hdoj 1874 畅通工程续 【最短路径】
- map与unordered_map
- Windows 7系统安装MySQL5.5.21图解
- select、poll、epoll之间的区别总结[整理]
- Device Tree(一):背景介绍
- js菜鸟正则表达式和function类型