模拟退火求n个点到某点距离和最短

该博客介绍了一种使用模拟退火算法来寻找n个点到某点距离和最短的解决方案,即最小覆盖圆的中心。通过不断迭代和调整步长,确定最优半径和中心坐标,从而找到使所有点到该点距离之和最小的圆。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
找出一个点使得这个店到n个点的最长距离最短,即求最小覆盖圆的半径
用一个点往各个方向扩展,如果结果更优,则继续以当前步长扩展,否则缩小步长
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
const double pi = acos(-1.0);
struct point {
    double x,y;
}p[1010];
int n;
point mid,tmid;
double R,xmin,ymin,xmax,ymax;
double ans,tans;
double dis(point a, point b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
void solve(double x,double y)
{
    double max=0;
    point tp;
    tp.x=x;
    tp.y=y;
    for(int i=0;i<n;i++)
    {
        double tmp=dis(p[i],tp);
            if(tmp>max)
                max=tmp;
    }
    if(max<tans)
    {
        tans=max;
        tmid=tp;
    }
}
int main()
{
    int X,Y,i,k;
    double j;
    while(scanf("%d%d%d",&X,&Y,&n)!=EOF)
    {
       // printf("n=%d\n",n);
        xmin=10000;ymin=10000;xmax=0;ymax=0;
        for(i=0;i<n;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
            if(p[i].x<xmin) xmin=p[i].x;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值