• poj2420(模拟退火大法好)


    //
    //  main.cpp
    //  poj2420
    //
    //  Created by 陈加寿 on 16/2/13.
    //  Copyright © 2016年 chenhuan001. All rights reserved.
    //
    
    #include <iostream>
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    struct Point
    {
        int x,y;
    }g[110];
    #define eps 1e-6
    
    double myrand()
    {
        long long a=rand();
        long long b=rand();
        a = a*b%200000-100000;
        return ((double)a/10);
    }
    
    double fuc(double x,double y,int n)
    {
        double sum=0;
        for(int i=0;i<n;i++)
            sum += sqrt( (x-g[i].x)*(x-g[i].x)+(y-g[i].y)*(y-g[i].y) );//不是哈密顿距离
        return sum;
    }
    
    double cold(int n)
    {
        double tx=0,ty=0;
        double K=1;
        double min=fuc(tx,ty,n);
        while(K>eps)
        {
            double xx,yy;
            xx=myrand()*K+tx;
            yy=myrand()*K+ty;
            double tmp=fuc(xx,yy,n);
            if( tmp < min )
            {
                min=tmp;
                tx=xx;
                ty=yy;
            }
            K*=0.98;
        }
        return min;
    }
    
    int main(int argc, const char * argv[]) {
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&g[i].x,&g[i].y);
        }
        double ans = 1e9;
        ans = min(ans,cold(n));
        printf("%.0lf
    ",ans);
        return 0;
    }
    

      

  • 相关阅读:
    goreplay~基本知识
    goreplay~http输出队列
    goreplay~拦截器设置
    goreplay~流量变速
    goreplay~http过滤参数
    goreplay~文件输出解析
    goreplay~http输出工作线程
    Antlr4 语法解析器(下)
    2021最新版Eclipse的下载和使用
    MySQL中drop、truncate和delete的区别
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/5188378.html
Copyright © 2020-2023  润新知