poj2420A Star not a Tree?(模拟退火)
求某一点到其它点距离和最小,求这个和,这个点 为费马点。
做法:模拟退火
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y =):x(x),y(y){}
}p[N];
int n;
int dir[][] = {,,,-,,,-,};
typedef point pointt;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
double cal(point pp)
{
int i;
double s = ;
for(i = ; i <= n; i++)
s+=dis(pp-p[i]);
return s;
}
int main()
{
int i;
while(scanf("%d",&n)!=EOF)
{
double t = ;
point pp = point(,);
for(i = ; i <= n;i ++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
pp.x+=p[i].x;
pp.y+=p[i].y;
}
pp.x /=n;
pp.y /=n;
double sum = cal(pp),tmp;
point tp,ans = pp;
while(t>0.02)
{
int flag = ;
while(flag)
{
flag = ;
for(i = ; i< ; i++)
{
tp = point(pp.x+dir[i][]*t,pp.y+dir[i][]*t);
tmp = cal(tp);
if(tmp<sum)
{
sum = tmp;
flag = ;
ans = tp;
}
}
pp = ans;
}
t/=;
}
printf("%.0f\n",sum);
}
return ;
}
poj2420A Star not a Tree?(模拟退火)的更多相关文章
- uva 10228 - Star not a Tree?(模拟退火)
题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...
- poj-2420 A Star not a Tree?(模拟退火算法)
题目链接: A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5219 Accepte ...
- POJ 2420 A Star not a Tree?(模拟退火)
题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...
- Poj2420 A Star not a Tree? 模拟退火算法
题目链接:http://poj.org/problem?id=2420 题目大意:每组数据中给n个点(n<=100),求平面中一个点使得这个点到n个点的距离之和最小. 分析:一开始看到这个题想必 ...
- poj2420 A Star not a Tree? 模拟退火
题目大意: 给定n个点,求一个点,使其到这n个点的距离最小.(\(n \leq 100\)) 题解 模拟退火上 #include <cmath> #include <cstdio&g ...
- POJA Star not a Tree?(模拟退火)
题意 题目链接 给出$n$个点,求出一个点使得到各个点的距离之和最小,距离为欧几里得距离 Sol 模拟退火真是玄学,我退了一上午,最后把exp函数去了就A了. 后来改了改,发现是大小符号的问题.. 但 ...
- poj 2420 A Star not a Tree? —— 模拟退火
题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...
- poj 2420 A Star not a Tree?——模拟退火
题目:http://poj.org/problem?id=2420 精度设成1e-17,做三遍.ans设成double,最后再取整. #include<iostream> #include ...
- poj2420 A Star not a Tree? 找费马点 模拟退火
题目传送门 题目大意: 给出100个二维平面上的点,让你找到一个新的点,使这个点到其他所有点的距离总和最小. 思路: 模拟退火模板题,我也不懂为什么,而且一个很有意思的点,就是初始点如果是按照我的代码 ...
随机推荐
- Ultra-QuickSort 分类: POJ 排序 2015-08-03 15:39 2人阅读 评论(0) 收藏
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 48111 Accepted: 17549 ...
- Python相对路径转绝对路径,绝对路径转相对路径
1.绝对路径转相对路径 print os.path.relpath("d:/MyProj/MyFile.txt") #..\MyProj\MyFile.txt 是根据当前路径的相对 ...
- ural 1110,快速幂
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1110 题意: X^N % M = Y,X=[0,M-1];没有输出-1: #incl ...
- boost库学习之开篇
本系列文章使用boost_1.58.0版本. 一.欢迎使用boost C++库 boost致力于提供一个免费的.便携的源代码级的库. 我们重视那些与C++标准一起工作良好的库.boost库将要成为一个 ...
- Application_Error异常处理
/// <summary> /// 捕捉异常 /// </summary> protected void Application_Error() { // 获得前一个异常的实例 ...
- flask安装
Flask简介 Flask算是小型框架,自开发伊始就被设计为可扩展的框架,它具有一个包含基本服务的强健核心.Flask有两个依赖:路由.调试.和web服务器网关接口(Web Server Gatewa ...
- 2016年12月3日 星期六 --出埃及记 Exodus 20:24
2016年12月3日 星期六 --出埃及记 Exodus 20:24 "`Make an altar of earth for me and sacrifice on it your bur ...
- 模块"xxxx.dll"已加载,但对DllRegisterServer的调用失败,错误代码为 XXXXXXXXX
WIN7.WIN8 注册 卸载dll 报错: 模块"xxxx.dll"已加载,但对DllRegisterServer的调用失败,错误代码为 XXXXXXXXX 解决方法: 若为 ...
- java导出cvs文件
package testcvs; import java.io.BufferedWriter;import java.io.File;import java.io.FileOutputStream;i ...
- xshell无法连接centos 6.6的问题
最近在做MySQL集群配置的预研工作,需要在VirtualBox上安装CentOS 6.6.参照网上的教程安装好centos后,出现了一个问题:虚拟机外部的文本内容无法复制粘贴到CentOS的终端里去 ...