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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5017】Ellipsoid(爬山算法,模拟退火,三分)

發(fā)布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5017】Ellipsoid(爬山算法,模拟退火,三分) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

Given a 3-dimension ellipsoid(橢球面)


your task is to find the minimal distance between the original point (0,0,0) and points on the ellipsoid. The distance between two points (x?1,y?1,z?1) and (x?2,y?2,z?2) is defined as?

Input

There are multiple test cases. Please process till EOF.

For each testcase, one line contains 6 real number a,b,c(0 < a,b,c,< 1),d,e,f?(0 ≤ d,e,f < 1), as described above.?It is guaranteed that the input data forms a ellipsoid.?All numbers are fit in double.

Output

For each test contains one line. Describes the minimal distance. Answer will be considered as correct if their absolute error is less than 10?-5.

Sample Input

1 0.04 0.01 0 0 0

Sample Output

1.0000000

題目大意:

求橢圓上離圓心最近的點的距離。

解題報告:

? 先解方程,然后模擬退火。但是發(fā)現(xiàn)這個題無論如何也調(diào)不出樣例,無奈改爬山算法。(正解是三分)

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; const double eps = 1e-10; const double GG = 12398734577LL; const int MAX = 2e5 + 5; int nx[8] = {1,1,1,0,0,-1,-1,-1}; int ny[8] = {1,0,-1,1,-1,1,0,-1}; double a,b,c,d,e,f; //double Rand(){return rand()%(RAD+1)/(1.0*RAD);}//隨機(jī)產(chǎn)生0-1的浮點數(shù) double calz(double x,double y) {double A=c,B=(d*y+e*x),C=f*x*y+a*x*x+b*y*y-1;double det = B*B-4*A*C;if(det < 0) return GG;double z1 = (-B+sqrt(det))/(2*A);double z2 = (-B-sqrt(det))/(2*A);if(fabs(z1)<fabs(z2)) return z1;else return z2; // return min(z1,z2); } double solve(double curx,double cury) {curx=0,cury=0;double T = 1,ansdis = GG;while(T>eps) {for(int i = 0; i<8; i++) {double tx = curx + nx[i]*T;double ty = cury + ny[i]*T;double tz = calz(tx,ty);if(fabs(tz-GG) < eps) continue;double tmpdis = sqrt(tx*tx+ty*ty+tz*tz);if(tmpdis < ansdis) {ansdis = tmpdis;curx = tx;cury = ty;}}T*=0.99;}return ansdis; } int main() {while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)) {double ans = 12312312313LL;ans = min(ans,solve(1/sqrt(a),0));ans = min(ans,solve(0,1/sqrt(b)));printf("%.6f\n",ans);}return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【HDU - 5017】Ellipsoid(爬山算法,模拟退火,三分)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。