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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj 2069 Super Star 模拟退火

發布時間:2023/12/18 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 2069 Super Star 模拟退火 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目大意:

給定三位空間上的n(\(n \leq 30\))個點,求最小的球覆蓋掉所有的點.

題解:

貌似我們可以用類似于二維平面中的隨機增量法瞎搞一下
但是我不會怎么搞
所以我們模擬退火就好了啊QAQ

#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; inline void read(int &x){x=0;char ch;bool flag = false;while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x; } inline int cat_max(const int &a,const int &b){return a>b ? a:b;} inline int cat_min(const int &a,const int &b){return a<b ? a:b;} const int maxn = 45; const double eps = 1e-15; const double det = 0.99; struct Point{double x,y,z;Point(const double &a=0,const double &b=0,const double &c=0){x=a;y=b;z=c;} }; inline double dis(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.z-b.z)*(a.z-b.z)); } int n;double ans = 1e100; Point p[maxn]; inline double f(const Point &x){double ret = 0;for(int i=1;i<=n;++i) ret = max(ret,dis(x,p[i]));if(ret < ans) ans = ret;return ret; } inline double ran(){return (rand() % 1000 + 1)/1000.0; } Point nw; int main(){srand(2333);while(1){read(n);if(n == 0) break;nw.x = nw.y = nw.z = 0;ans = 1e100;for(int i=1;i<=n;++i){scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);}double T = 100.0,x;double dist;int pos;while(T > eps){dist = 0.0;for(int i=1;i<=n;++i){if(dist < dis(nw,p[i])){pos = i;dist = dis(nw,p[i]);}}Point nx(nw.x+(p[pos].x-nw.x)/dist*T,nw.y+(p[pos].y-nw.y)/dist*T,nw.z+(p[pos].z-nw.z)/dist*T);x = f(nw) - f(nx);if(x > 0 || exp(x/T) > ran()) nw = nx;T *= det;}printf("%.5lf\n",ans);}getchar();getchar();return 0; }

轉載于:https://www.cnblogs.com/Skyminer/p/6438262.html

總結

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

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