题目

传送门:QWQ

分析

军训完状态不好QwQ,做不动难题,于是就学了下模拟退火。

之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂?

骗分利器,但据说由于调参困难,很多情况比不上多点爬山?

总体来说模拟退火的精髓就是:

可以看到T越大,转移的概率越高。 exp是在cmath里面有的,直接用就ok。

本题就是找出n个点的费马点,即找出一个点到这n个点的距离和最小。

代码

 // #include <bits/stdc++.h>
// POJ 2420
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
const int maxn=;
const double pace=0.95;
struct Point { double x,y; }; int n;
Point p[maxn]; double sqr(double x){ return x*x; }
double dis(double x,double y,Point a){ return sqrt(sqr(x-a.x)+sqr(y-a.y)); }
double getnum(double x,double y){
double ans=;
for(int i=;i<=n;i++) ans+=dis(x,y,p[i]);
return ans;
}
int main(){
// srand(time(NULL));
srand();
Point ans;
scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%lf%lf",&p[i].x,&p[i].y);
ans.x+=p[i].x; ans.y+=p[i].y;
}
ans.x/=n; ans.y/=n;
double t=1e5, end=0.02, pre=getnum(ans.x,ans.y);
while(t>end){ double xx=, yy=;
t*=pace;
for(int i=;i<=n;i++){
xx+=(p[i].x-ans.x)/dis(ans.x,ans.y,p[i]);
yy+=(p[i].y-ans.y)/dis(ans.x,ans.y,p[i]);
}
double tmp=getnum(ans.x+xx*t,ans.y+yy*t);
if(tmp<pre){
pre=tmp; ans.x+=xx*t; ans.y+=yy*t;
}
else if(exp((pre-tmp)/t)>(rand()%)/10000.0){
ans.x+=xx*t; ans.y+=yy*t;
}
t*=pace;
}
printf("%.0f",pre);
return ;
}

【POJ】2420 A Star not a Tree?(模拟退火)的更多相关文章

  1. poj 2420 A Star not a Tree? —— 模拟退火

    题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...

  2. poj 2420 A Star not a Tree?——模拟退火

    题目:http://poj.org/problem?id=2420 精度设成1e-17,做三遍.ans设成double,最后再取整. #include<iostream> #include ...

  3. POJ 2420 A Star not a Tree?(模拟退火)

    题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...

  4. 三分 POJ 2420 A Star not a Tree?

    题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...

  5. [POJ 2420] A Star not a Tree?

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4058   Accepted: 200 ...

  6. POJ 2420 A Star not a Tree? (计算几何-费马点)

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3435   Accepted: 172 ...

  7. POJ 2420 A Star not a Tree? 爬山算法

    B - A Star not a Tree? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...

  8. POJ 2420 A Star not a Tree?【爬山法】

    题目大意:在二维平面上找出一个点,使它到所有给定点的距离和最小,距离定义为欧氏距离,求这个最小的距离和是多少(结果需要四舍五入)? 思路:如果不能加点,问所有点距离和的最小值那就是经典的MST,如果只 ...

  9. uva 10228 - Star not a Tree?(模拟退火)

    题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...

随机推荐

  1. cobbler网络装机

    cobbler网络装机 原理分析 cobbler简介 Cobbler通过将设置和管理一个安装服务器所涉及的任务集中在一起,从而简化了系统配置.相当于Cobbler封装了DHCP.TFTP.XINTED ...

  2. 空格填充器(alignBySpace)

    /******************************************************************* * 空格填充器(alignBySpace) * 声明: * 1 ...

  3. Fire Game 双向bfs

    Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...

  4. echar生成雷达图

    function createRadarChart(indicatorData, personData) { var myChart = echarts.init(document.getElemen ...

  5. solr 6.2.1环境搭建

    一:Solr简介 Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引:也可以通过 ...

  6. Cocos2d-x 2.2.3 使用NDK配置编译环境

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/wwj_748/article/details/30072379 Cocos2d-x 2.2.3 使用 ...

  7. Linux小问题以及解决方案

    1.Linux的时间有问题? ntpdate pool.ntp.org 2.要把一条命令开机执行开机 vim /etc/rc.local 添加要执行的命令 3.系统中网络进程的端口监听情况: nets ...

  8. 记录 ThinkPHP 5.* 漏洞修复后的情况

    记录 ThinkPHP 5.* 漏洞修复后的情况 ThinkPHP 官方 2018-12-09 下午收到漏洞报告. 2018-12-09 晚上看到 Git 已经更新了,修复了漏洞. 2018-12-1 ...

  9. zstack(一)运行及开发环境搭建及说明(转载)

    本篇介绍zstack的部署环境,以及二次开发环境 运行环境 讲真,ZStack的安装做的还是不错的,提供多种安装模式,如离线安装.在线安装.一键安装.分布式安装等.安装的过程其实都很简单,当然这也是z ...

  10. python之 列表常用方法

    更多列表的使用方法和API,请参考Python文档:http://docs.python.org/2/library/functions.html append:用于在列表末尾追加新对象: # app ...