poj 2420 A Star not a Tree? 模拟退火
来源:互联网 发布:淘宝可以买凤楼信息吗 编辑:程序博客网 时间:2024/05/23 15:12
题目大意:在多边形中找一个点,让这个点距离所有点的距离和最短。
模拟退火,选一个随机点,朝上,下,左,右四个点移动
代码:
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#define maxn 100+10#define sqr(x) ((x)*(x))#define F(i,n) for(int i=0;i<n;i++)#define eps 1e-3#define pi acos(-1.0)#define Min(a,b) a>b?b:ausing namespace std;int dr[4][2]={-1,0,0,-1,1,0,0,1};struct cpoint{double x,y,d;cpoint(){
d=0;}
};cpoint cp[maxn],rp;int n;double dis(cpoint p,cpoint q){return sqrt(sqr(p.x-q.x)+sqr(p.y-q.y));}
void solve(){rp=cp[0];rp.d=0;F(i,n)rp.d+=dis(rp,cp[i]); //printf("rp :%lf\n",rp.d);double dal=10000;while(dal>0.2){cpoint t;F(j,4){t.x=rp.x+dal*dr[j][0];t.y=rp.y+dal*dr[j][1];if(t.x>10000||t.x<0||t.y>10000||t.y<0)continue;t.d=0;F(k,n){t.d+=dis(t,cp[k]);} //printf("d :%lf\n",t.d);if(rp.d>t.d)rp=t;}dal*=0.5;}printf("%d\n",(int)(rp.d+0.5)*100/100);}
int main(){while(scanf("%d",&n)!=EOF){F(i,n)scanf("%lf %lf",&cp[i].x,&cp[i].y);solve();}return 0;}
- POJ 2420 A Star not a Tree? 费马点,模拟退火
- poj 2420 A Star not a Tree? 模拟退火
- poj 2420 A Star not a Tree?(模拟退火求费马点)
- poj 2420 A Star not a Tree?(模拟退火)
- [poj 2420]A Star not a Tree?[模拟退火]
- poj 2420 A Star not a Tree?(模拟退火)
- POJ 2420 A Star not a Tree? (简单模拟退火)
- POJ 2420 A Star not a Tree? (模拟退火)
- poj 2420 A Star not a Tree? -- 模拟退火
- poj 2420 A Star not a Tree? 模拟退火
- 【POJ 2420】 A Star not a Tree?(模拟退火)
- POJ,2420 A Star not a Tree?(模拟退火算法)
- POJ 2420 A Star not a Tree? (模拟退火)
- POJ 2420 A Star not a Tree? (模拟退火)
- poj 2420 A Star not a Tree? (模拟退火)
- 【POJ】【P2420】【A Star not a Tree?】【题解】【模拟退火】
- A Star not a Tree? 模拟退火
- POJ 1379 Run away & POJ 2420 A star not a Tree [模拟退火] [爬山算法]
- VMware Workstation - RAC的共享磁盘设置
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
- Oracle 10G RAC - SYSAUX进行完全恢复的问题
- poj 2069 super star 模拟退火
- HDOJ 1712 ACboy needs your help (分组背包)
- poj 2420 A Star not a Tree? 模拟退火
- 如何高效地阅读技术类书籍与博客
- PL/Sql 连接数据库 超时问题解决
- Oracle 10G RAC与10G Physical DG 的测试-1
- Oracle 10G RAC与10G Physical DG 的测试-2
- ORA-12170 TNS 连接超时 .
- void在C/C++中的两种不同含义
- Oracle 10G RAC Clusterware Install ERROR:OCR integrity results are inconsistent amongst the nodes.
- Oracle 无法监听 因目标主机或对象不存在 连接失败--解决方案