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个二维平面上的点,让你找到一个新的点,使这个点到其他所有点的距离总和最小. 思路: 模拟退火模板题,我也不懂为什么,而且一个很有意思的点,就是初始点如果是按照我的代码 ...
随机推荐
- HDU 1728:逃离迷宫(BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有 ...
- sql server 快捷键
书签:清除所有书签. CTRL-SHIFT-F2 书签:插入或删除书签(切换). CTRL+F2 书签:移动到下一个书签. F2 功能键 书签:移动到上一个书签. SHIFT+F2 取消查询. ALT ...
- 通达OA 指纹考勤机接口 源代码
通达oa2011已经支持 指纹考勤机 但只限中控iclock660 这款2000大洋的型号 通过本文的开发接口,可以与任意一款指纹机集成, 需求指纹机管理软件能实时保存数据 我这里用的是 中控u16 ...
- RMAN笔记小结
首先感谢junsansi和leshani两位大师的文笔:我可是好好看了很多遍:这两位哦:我跟你们说:对rman的解说那是相当精彩:文章形如流水,通俗易懂:内容那是入木三分...;好了我也不多说了,反正 ...
- LA 4064 Magnetic Train Tracks
题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...
- The Cow Lexicon
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8815 Accepted: 4162 Descr ...
- python递归小疑惑
代码如下: def crawlAndGet(keyword, n): if n>0: jsondata = os.system('scrapy crawl beijing -a store_di ...
- spoj LCMSUM sigma(lcm(i,n));
Problem code: LCMSUM Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) ...
- 华东交通大学2016年ACM“双基”程序设计竞赛 1010
Problem Description LB是个十分喜欢钻研的人,对什么事都要搞明白.有一天他学习到了阶乘,他十分喜欢,所以他在想一个问题.如果给定一个数n,求n!能不能被2016整除.LB算了好久都 ...
- linux Centos 6.5 FTP服务原理及vsfptd的安装、配置(转)
本篇随笔将讲解FTP服务的原理以及vsfptd这个最常用的FTP服务程序的安装与配置... 一.FTP服务原理 FTP(File Transfer Protocol)是一个非常古老并且应用十分广泛的文 ...