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? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...
随机推荐
- jquery判断复选框是否被选中
$("#isUse").click(function(){ if($(this).is(':checked')){ $(this).attr('checked','checked' ...
- 深入浅出Attribute(三)
约定: 1.”attribute”和”attributes”均不翻译 2.”property”译为“属性” 3.msdn中的原句不翻译 4.”program entity”译为”语言元素” Attri ...
- 给定一个递增序列,a1 <a2 <...<an 。定义这个序列的最大间隔为d=max{ai+1 - ai }(1≤i<n),现在要从a2 ,a3 ..an-1 中删除一个元素。问剩余序列的最大间隔最小是多少?
// ConsoleApplication5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<vector> ...
- vue 流程设计器
github地址:https://github.com/280780363/gucflow.designer demo地址:https://280780363.github.io/gucflow.de ...
- NDK以及C语言基础语法(一)
一.什么是NDK? Native Development Kit (本地开发工具包): NDK中提供了一系列的工具,帮助我们快速开发C/C++的动态库,并能自动将so文件和java文件一起打包成apk ...
- MongoDB在win7上的安装(精简版)
1.下载mongdb的zip文件,解压后会发现有bin文件夹,在同层目录下建一个data目录, 2.在data目录下建一个log和db文件夹, 3.在log文件下建一个MongoDB.log 文件 4 ...
- 九度OJ 1152:点菜问题 (01背包、DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1046 解决:543 题目描述: 北大网络实验室经常有活动需要叫外买,但是每次叫外买的报销经费的总额最大为C元,有N种菜可以点,经过长时间的 ...
- git修改commit说明
当发现说明写错了时,执行git commit --amend,然后修改说明即可.
- c++中的基本知识点
1 class和struct的区别和联系 在c++中,class和struct只有一点不同,它们是可以完全替代使用的.唯一的不同在于,class中的成员默认是private的,而struct中默认是p ...
- weblogic开启远程访问的jmx设置
通过jmx远程访问weblogic获取监控jvm的数据,要在weblogic启动的时候设置一些配置,具体如下: 在weblogic的安装目录:{weblogic_home}/wlserver_10.3 ...