日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

poj 1379 模拟退火法

發布時間:2025/6/17 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 1379 模拟退火法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/* 模擬退火法:找到一些隨機點,從這些點出發,隨機的方向坐標向外搜索;最后找到這些隨機點的最大值;坑://if(xx>-eps&&xx<x+eps&&yy>-eps&&yy<eps+y) {不知道為什么這個判斷方式錯誤?????? */ #include<iostream> #include<cstdio> #include<math.h> #include<algorithm> #define pi acos(-1.0) #define N 1100 #define inf 1000000000000 #define eps 1e-8 using namespace std; double x,y; int n; struct node { double u,v,dis; }f[N],endd,ff[N]; double diss(double x,double y,int i) {return sqrt((x-f[i].u)*(x-f[i].u)+(y-f[i].v)*(y-f[i].v)); } double Mindis(double x,double y) {double minn=1.0*inf,ss;int i;for(i=1;i<=n;i++) {ss=diss(x,y,i);if(minn>ss)minn=ss;}return minn; } void compute() {int i,j;double xx,yy;for(i=1;i<=20;i++) {//先隨機出來一些點ff[i].u=(rand()%1000+1)/1000.0*x;ff[i].v=(rand()%1000+1)/1000.0*y;ff[i].dis=Mindis(ff[i].u,ff[i].v);}double T=sqrt(1.0*x*x+1.0*y*y);double rate=0.9;while(T>eps) {for(i=1;i<=20;i++)//對于這些點分別向外搜for(j=1;j<=30;j++) {//隨機30個半徑來搜索,更新,得到每個點可以到達的最遠距離double ran=(rand()%1000+1)/1000.0*pi*10;xx=ff[i].u+cos(ran)*T;yy=ff[i].v+sin(ran)*T;//if(xx>-eps&&xx<x+eps&&yy>-eps&&yy<eps+y) {不知道為什么這個判斷方式錯誤??????if(xx<0.0||xx>x||yy<0.0||yy>y)continue;double di=Mindis(xx,yy);if(ff[i].dis<di) {ff[i].dis=di;ff[i].u=xx;ff[i].v=yy;}}T*=rate;//退火率}for(i=1;i<=20;i++)//找到最大的一個if(endd.dis<ff[i].dis)endd=ff[i];return ; } int main() {// printf("%d\n",(rand()%1000+1)/1000.0*2*pi);int m,i,j,k,t;scanf("%d",&t);while(t--) {scanf("%lf%lf%d",&x,&y,&n);for(i=1;i<=n;i++)scanf("%lf%lf",&f[i].u,&f[i].v);endd.dis=-1;compute();printf("The safest point is (%.1f, %.1f).\n",endd.u,endd.v);} return 0; }

轉載于:https://www.cnblogs.com/thefirstfeeling/p/4410615.html

總結

以上是生活随笔為你收集整理的poj 1379 模拟退火法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。