//
// 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\n",ans);
return 0;
}

  

poj2420(模拟退火大法好)的更多相关文章

  1. 【清华集训 2017】小Y的地铁 [模拟退火]

    小Y的地铁 Time Limit: 50 Sec  Memory Limit: 256 MB Description Input Output 对于每组输入数据,输出一行一个整数,表示除掉这 n 个换 ...

  2. 「Luogu P2278」[HNOI2003]操作系统 解题报告

    题面 一道模拟题,模拟CPU的处理过程?!省选模拟题 思路: 模拟退火大法+优先队列乱搞 要注意的点 1.空闲时,CPU要处理进程 2.当队列中没有进程时,要先进行判断,然后访问 3.当优先级高的进程 ...

  3. Poj2420 A Star not a Tree? 模拟退火算法

    题目链接:http://poj.org/problem?id=2420 题目大意:每组数据中给n个点(n<=100),求平面中一个点使得这个点到n个点的距离之和最小. 分析:一开始看到这个题想必 ...

  4. 初探 模拟退火算法 POJ2420 HDU1109

    模拟退火算法来源于固体退火原理,更多的化学物理公式等等这里不再废话,我们直接这么来看 模拟退火算法简而言之就是一种暴力搜索算法,用来在一定概率下查找全局最优解 找的过程和固体退火原理有所联系,一般来讲 ...

  5. 【模拟退火】poj2420 A Star not a Tree?

    题意:求平面上一个点,使其到给定的n个点的距离和最小,即费马点. 模拟退火的思想是随机移动,然后100%接受更优解,以一定概率接受更劣解.移动的过程中温度缓慢降低,接受更劣解的概率降低. 在网上看到的 ...

  6. POJ-2420 A Star not a Tree? 梯度下降 | 模拟退火

    题目链接:https://cn.vjudge.net/problem/POJ-2420 题意 给出n个点,找一个点,使得这个点到其余所有点距离之和最小. 思路 一开始就在抖机灵考虑梯度下降,猜测是个凸 ...

  7. [POJ2420]A Star not a Tree?(模拟退火)

    题目链接:http://poj.org/problem?id=2420 求费马点,即到所有其他点总和距离最小的点. 一开始想枚举一个坐标,另一个坐标二分的,但是check的时候还是O(n)的,复杂度相 ...

  8. poj2420 A Star not a Tree? 找费马点 模拟退火

    题目传送门 题目大意: 给出100个二维平面上的点,让你找到一个新的点,使这个点到其他所有点的距离总和最小. 思路: 模拟退火模板题,我也不懂为什么,而且一个很有意思的点,就是初始点如果是按照我的代码 ...

  9. poj-2420 A Star not a Tree?(模拟退火算法)

    题目链接: A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5219   Accepte ...

随机推荐

  1. c# 用OpenXmL读取.xlsx格式的Excel文件 返回DataTable

    1.须要引用的dll :  DocumentFormat.OpenXml.dll  ---须要安装一下OpenXml再引用 WindowsBase  ---直接在项目里加入引用 2.方法: /// & ...

  2. eval(data)和eval("("+data+")")的区别

    如果data是字符串,使用eval("("+data+")")可以将其转换为json对象,和JSON.parse的功能一样.如果data是json对象,使用ev ...

  3. MySQL错误Another MySQL daemon already running with the same unix socket.v

    etc/init.d/mysqld start 结果显示 Another MySQL daemon already running with the same unix socket.显示另一个MyS ...

  4. lodash 判断相等 eq isEqual

    var object = { 'a': 1 }; var other = { 'a': 1 }; //true console.log(_.eq(object, object)) //true con ...

  5. JUnit4.8.2源码分析-1 说明

    阅读本系列文章时须要知道的: JUnit是由GOF 之中的一个的Erich Gamma和 Kent Beck 编写的一个开源的单元測试框架,分析JUnit源码的主要目的是学习当中对设计模式的运用.JU ...

  6. Python中函数参数传递问题【转】

    1. Python passes everything the same way, but calling it "by value" or "by reference& ...

  7. VC 使用json cpp 静态库 问题解决

    release使用 json 静态库 提示 fatal error C1083: 无法打开编译器生成的文件:“../../build/vs71/release/lib_json\json_writer ...

  8. 【MyBatis学习08】高级映射之一对一查询

    从这一篇博文开始,将总结一下mybatis中的几个高级映射,即一对一.一对多.多对多查询,这篇先总结一下mybatis中的一对一查询.  为了模拟这些需求,事先要建立几个表,不同的表之间将对应上面提到 ...

  9. unity, UGUI Text fadeIn

    错误写法: Color color = m_text.GetComponent<Text> ().color;        Color startColor = new Color (c ...

  10. 在CentOS 6.3中安装拼音输入法

    安装:su root yum install "@Chinese Support"      // 安装中文输入法 exit安装完毕,在“系统-->首选项”会看到“输入法”一 ...