poj 2420 A Star not a Tree?——模拟退火
题目:http://poj.org/problem?id=2420
精度设成1e-17,做三遍。ans设成double,最后再取整。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<ctime>
#define db double
using namespace std;
const int N=;
const db dc=0.99,eps=1e-;
int n,nx[N],ny[N];
db px,py,ans;
db dis(db x0,db y0,db x1,db y1)
{
return sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
db calc(db x,db y)
{
db ret=;
for(int i=;i<=n;i++)ret+=dis(nx[i],ny[i],x,y);
return ret;
}
db gtrd(db T){return (rand()*-RAND_MAX)*T;}
void SA(db T)
{
db x0=px,y0=py,pr=calc(x0,y0),x,y,cr;
while(T>eps)
{
x=x0+gtrd(T); y=y0+gtrd(T); cr=calc(x,y);
if(cr<pr||(exp((cr-pr)/T)*RAND_MAX<rand()))
{
ans=min(ans,cr);
x0=x;y0=y;pr=cr;
}
T*=dc;
}
}
int main()
{
srand(time());
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&nx[i],&ny[i]),px+=nx[i],py+=ny[i];
px/=n; py/=n; ans=calc(px,py);
SA();SA();SA();
printf("%.0lf\n",ans);
return ;
}
poj 2420 A Star not a Tree?——模拟退火的更多相关文章
- poj 2420 A Star not a Tree? —— 模拟退火
		题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ... 
- POJ 2420 A Star not a Tree?(模拟退火)
		题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ... 
- 三分 POJ 2420 A Star not a Tree?
		题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ... 
- [POJ 2420] A Star not a Tree?
		A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ... 
- POJ 2420 A Star not a Tree? (计算几何-费马点)
		A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3435 Accepted: 172 ... 
- 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 ... 
- POJ 2420 A Star not a Tree?【爬山法】
		题目大意:在二维平面上找出一个点,使它到所有给定点的距离和最小,距离定义为欧氏距离,求这个最小的距离和是多少(结果需要四舍五入)? 思路:如果不能加点,问所有点距离和的最小值那就是经典的MST,如果只 ... 
- 【POJ】2420 A Star not a Tree?(模拟退火)
		题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ... 
- uva 10228 - Star not a Tree?(模拟退火)
		题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ... 
随机推荐
- 看完这篇还不会自定义 View ,我跪搓衣板
			自定义 View 在实际使用的过程中,我们经常会接到这样一些需求,比如环形计步器,柱状图表,圆形头像等等,这时我们通常的思路是去Google 一下,看看 github 上是否有我们需要的这些控件,但是 ... 
- javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist:
			javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity pas ... 
- window+Jira+SQL Server
			window下Jira+SQL Server部署+汉化+破解(亲测2018.5) 网上很多都是jira+mysql部署的文章,由于我现在有需求要用SQL Server数据库,因此就动手试了一下,参考网 ... 
- Process Stats:了解你的APP怎样使用内存
			原文地址:http://android-developers.blogspot.com/2014/01/process-stats-understanding-how-your.html?m=1 原作 ... 
- 基于EasyDarwin框架实现EasyNVR H5无插件直播流媒体服务器方案
			在之前的一篇博客<web无插件播放RTSP摄像机方案,拒绝插件,拥抱H5!>中,描述了实现一套H5无插件直播方案的各个组件的参考建议,又在博客<EasyNVR H5流媒体服务器方案架 ... 
- EasyRTMP Android安卓手机直播推流摄像头偏暗的问题解决
			在我们测试EasyRTMP Android安卓手机推流的过程中发现有些设备预览时,明显偏暗!在稍微暗点的环境中几乎很难看清东西-额,这是怎么回事呢?又是安卓设备的兼容性问题,头疼! !!!好吧,停止抱 ... 
- JAVA数据类型(转)
			java中数据的基本类型分为: 基本数据类型和引用数据类型,对此不多介绍: 接下来讨论一下java中数据类型存储在哪 基本数据类型存储在哪,取决于基本类型在哪声明: 1 ... 
- centos安装php5.6
			配置yum源 追加CentOS 6.5的epel及remi源. # rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel- ... 
- 我的Java开发学习之旅------>在Dos环境下Java内部类的编译和运行
			习惯了在IDE工具上进行代码编写,连最基本的Javac命令和Java命令都忘记的差不多了,今天对一个Java内部类进行编译和运行的时候,就出糗了.IDE是把双刃剑,它可以什么都帮你做了,你只要敲几行代 ... 
- debian7 amd64版本添加对x86包的支持
			dpkg --add-architecture i386apt-get updateapt-get install ia32-libs ia32-libs-gtk 
