poj 1379 模拟退火算法的应用
来源:互联网 发布:ubuntu如何共享文件夹 编辑:程序博客网 时间:2024/05/13 03:14
学习自http://blog.csdn.net/dooder_daodao/article/details/6336879
View Code
1 #include<stdio.h>
2 #include<math.h>
3 #include<stdlib.h>
4 #include<time.h>
5 const double inf = 1e10;
6 const double pi = acos(-1.0);
7 const int Rp = 4;
8 const int shift = 60;
9 struct point {
10 double x,y;
11 void goto_rand_dir(double key)
12 {
13 double d=2*pi*(double)rand()/RAND_MAX;
14 x+=key*sin(d);
15 y+=key*cos(d);
16 }
17 void Get_Rand_Point(int a,int b)
18 {
19 x=rand()%a+1;
20 y=rand()%b+1;
21 }
22 }p[1010],randp[Rp];
23 double Dis(point a,point b)
24 {
25 return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
26 }
27 double dis[Rp];
28 int main()
29 {
30 int t,i,j,k,x,y,m;
31 scanf("%d",&t);
32 srand(time(NULL));
33 while(t--)
34 {
35 scanf("%d%d%d",&x,&y,&m);
36 for(i=0;i<m;i++)
37 {
38 scanf("%lf%lf",&p[i].x,&p[i].y);
39 }
40 double tmp;
41 for(i=0;i<Rp;i++)
42 {
43 dis[i]=inf;
44 randp[i].Get_Rand_Point(x,y);
45 for(j=0;j<m;j++)
46 {
47 tmp=Dis(randp[i],p[j]);
48 if(tmp<dis[i])
49 dis[i]=tmp;
50 }
51 }
52 double key=sqrt(1.0*(x*x+y*y))/2;
53 while(key>=0.01)
54 {
55 for(i=0;i<Rp;i++)
56 {
57 for(j=0;j<shift;j++)
58 {
59 point cc=randp[i];
60 cc.goto_rand_dir(key);
61 if(cc.x<0||cc.y<0||cc.x>x||cc.y>y) continue;
62 tmp=inf;
63 for(k=0;k<m;k++)
64 {
65 double di=Dis(cc,p[k]);
66 if(di<tmp)
67 tmp=di;
68 }
69 if(tmp>dis[i])
70 {
71 dis[i]=tmp;
72 randp[i]=cc;
73 }
74 }
75 }
76 key=key*0.8;
77 }
78 for(i=k=0;i<Rp;i++)
79 if(dis[i]>dis[k])
80 k=i;
81 printf("The safest point is (%.1lf, %.1lf).\n",randp[k].x,randp[k].y);
82 }
83 return 0;
84 }
- poj 1379 模拟退火算法的应用
- POJ 1379 模拟退火算法
- POJ 1379 run away 模拟退火算法
- 模拟退火 poj 1379
- poj 1379 模拟退火
- POJ 1379 模拟退火
- POJ 1379模拟退火
- 模拟退火算法 POJ 2420
- POJ 1379 模拟退火的起点选择
- 模拟退火算法应用(Java)
- POJ, 1379Run Away(模拟退火算法)
- 对 模拟退火算法的理解 初步应用 以及 模板
- 模拟退火算法的基本原理
- 模拟退火算法的介绍
- "活"的模拟退火算法
- POJ 2420 二分法 模拟退火算法
- POJ, 2069 Super Star(模拟退火算法)
- POJ 1379 Run away & POJ 2420 A star not a Tree [模拟退火] [爬山算法]
- 2010 Asia Regional Tianjin Site —— Online Contest hdu 3622 Bomb Game 强连通 two sat
- http://www.cnblogs.com/UESTC_Opera/
- zoj 3551 dp求期望
- poj 2356 简单抽屉原理
- poj 3370 抽屉原理
- poj 1379 模拟退火算法的应用
- 2008 Asia Regional Beijing hdu 2485 destroying the bus station
- hdu 4055 dp
- 四色定理。。zoj 1084 channel allocation
- poj 2478 3090法雷级数初体验。。。
- poj 1679 判断最小生成树是否唯一
- hdu 4005 边双联通
- poj 2349 最小生成树
- hdu 2489 枚举m个点求最小生成树 2008 asia beijing regional contest