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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

HDU 3932 模拟退火

發布時間:2024/4/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 3932 模拟退火 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

HDU3932

?題目大意:給定一堆點,找到一個點的位置使這個點到所有點中的最大距離最小

簡單的模擬退火即可

?

1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <ctime> 7 #include <algorithm> 8 9 using namespace std; 10 11 #define N 1005 12 #define PI acos(-1.0) 13 #define random(x) (rand()%x+1) 14 const int P = 20; 15 const int L = 25; 16 double X,Y; 17 int n; 18 double mindis[N]; 19 20 struct Point{ 21 double x , y; 22 Point(double x=0 , double y=0):x(x),y(y){} 23 void input(){ 24 scanf("%lf%lf" , &x , &y); 25 } 26 }p[N] , tmp[N]; 27 28 double dis(Point a , Point b) 29 { 30 double x = a.x-b.x , y=a.y-b.y; 31 return sqrt(x*x+y*y); 32 } 33 34 double cal(Point a) 35 { 36 double maxn = 0; 37 for(int i=0 ; i<n ; i++) maxn = max(maxn , dis(a , p[i])); 38 return maxn; 39 } 40 41 int main() 42 { 43 #ifndef ONLINE_JUDGE 44 freopen("a.in" , "r" , stdin); 45 #endif // ONLINE_JUDGE 46 while(~scanf("%lf%lf%d" , &X , &Y , &n)) 47 { 48 for(int i=0 ; i<n ; i++) p[i].input(); 49 for(int i=0 ; i<P ; i++){ 50 tmp[i].x = random(1000)/1000.0*X; 51 tmp[i].y = random(1000)/1000.0*Y; 52 mindis[i] = cal(tmp[i]); 53 } 54 double step = sqrt(X*X+Y*Y)/2; 55 while(step>1e-3){ 56 for(int i=0 ; i<P ; i++){ 57 for(int j=0 ; j<L ; j++){ 58 Point cur; 59 double ang = random(1000)/1000.0*2*PI; 60 cur.x = tmp[i].x+cos(ang)*step; 61 cur.y = tmp[i].y+sin(ang)*step; 62 if(cur.x<0 || cur.x>X || cur.y<0 || cur.y>Y) continue; 63 double val = cal(cur); 64 if(val<mindis[i]){ 65 mindis[i] = val; 66 tmp[i] = cur; 67 } 68 } 69 } 70 step *= 0.85; 71 } 72 double ret = 1e20; 73 Point u; 74 for(int i=0 ; i<P ; i++){ 75 if(mindis[i]<ret){ 76 u = tmp[i]; 77 ret = mindis[i]; 78 } 79 } 80 printf("(%.1f,%.1f).\n%.1f\n" , u.x,u.y,ret); 81 } 82 return 0; 83 }

?

轉載于:https://www.cnblogs.com/CSU3901130321/p/4530595.html

總結

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

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