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 }
时间: 2024-08-04 13:23:20

HDU 3932 模拟退火的相关文章

HDU 3644 模拟退火

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3644 题意:给定n个点的一个多边形,一个圆的半径,判断圆是否可以放在多边形里, 由于圆形坐标没确定,所以采用模拟退火法来算,不断地减小步长,选取n个点,点在多边形内采用穿线法判断, 精度很坑爹,调了一下午精度,在wa与tle之间徘徊20+次,吐血AC. 代码: /* *********************************************** Author :rabbit Crea

hdu 3932 Groundhog Build Home —— 模拟退火

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 找一个位置使距离最远的点的距离最小: 上模拟退火: 每次向距离最远的点移动,注意判断一下距离最远的点距离为0的情况. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<cstdlib&

HDU - 3932 Groundhog Build Home 模拟退火算法

Groundhogs are good at digging holes, their home is a hole, usually a group of groundhogs will find a more suitable area for their activities and build their home at this area .xiaomi has grown up, can no longer live with its parents.so it needs to b

HDU 3932 Groundhog Build Home 【基础模拟退火】

和刚才那道是一模一样 不过求的是最小的,只要稍微修改一下就可以了~ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring> #include <cmath> #include <stack>

HDU 3932

http://acm.hdu.edu.cn/showproblem.php?pid=3932 一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以 这个问题又叫最小圆覆盖 #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <ctime> #include <cmath> using n

hdu 5017 模拟退火

题意:给出椭球面的立体解析式,要求椭球面上距离原点最近的点的距离 sol:这题要想推公式就??????...[可以试试二元函数求极值 一种比较普遍的解法是模拟退火 模拟退火的解释可以参考这儿:http://www.cnblogs.com/heaad/archive/2010/12/20/1911614.html 模拟退火模板get: 1 double sa() //Simulated_Annealing 2 { 3 double x = 0,y = 0,z = sqrt(1.0/C); //当前

hdu 3932 Groundhog Build Home

Groundhog Build Home Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2647    Accepted Submission(s): 1074 Problem Description Groundhogs are good at digging holes, their home is a hole, usually

平面点集的最小包围圆 hdu 3932

最小覆盖圆算法地址:http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066 平面点集的最小包围圆 1.           问题背景 考察固定在工作平台上的一直机械手,要捡起散落在不同位置的多个零件,并送到别的地方.那么,这只机械手的底座应该选在哪里呢?根据直觉,应该选在机械手需够着的那些位置的"中心".准确地讲,也就是包围这些点的那个最小圆的圆心----该位置的好处是,可使机械手的底座到它需要够着的那些点的最大距离最小化.于是可得如下问题:给

HDU 3007 模拟退火算法

Buried memory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4067    Accepted Submission(s): 2171 Problem Description Each person had do something foolish along with his or her growth.But,when