题目链接

居然1Y了,以前写的模拟退火很靠谱啊。

 #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
struct point
{
double x,y;
}p[];
int n;
int a[] = {,,-,};
int b[] = {,-,,};
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y2-y1)*(y2-y1));
}
double fun(double x,double y)
{
double ans = ;
int i;
for(i = ;i < n;i ++)
{
ans += dis(p[i].x,p[i].y,x,y);
}
return ans;
}
int main()
{
int T,i,key,num,j,k;
double tx,ty,ans,d,x,y;
srand(time(NULL));
scanf("%d",&n);
for(i = ;i < n;i ++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
key = ;
ans = ;
num = ;
x = p[].x;
y = p[].y;
T = ;
while(T--)
{
for(i = ;i <= num;i ++)
{
for(j = ;j < ;j ++)
{
k = rand()%key;
tx = x + k*a[j]*T;
ty = y + k*b[j]*T;
if(tx >= &&tx <= &&ty >= &&ty <= )
{
d = fun(tx,ty);
if(ans > d)
{
ans = d;
x = tx;
y = ty;
}
}
}
}
}
printf("%.f\n",ans);
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?

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

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

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

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

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

  6. 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 ...

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

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

  8. 【POJ】2420 A Star not a Tree?(模拟退火)

    题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ...

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

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

随机推荐

  1. Delphi字符串与字符数组之间的转换(初始化的重要性)

    紧接着上篇博客讲解的内容: 将Char型数组转换为string类型还有下面的这种方法 但是我在测试的时候遇到了一些问题,并在下面进行了解释和总结 先说出我的总结 其实我们在学习编程的时候(比如我之前学 ...

  2. Delphi中DLL的创建和使用

    参考:http://blog.csdn.net/ninetowns2008/article/details/6311663 结合这篇博客:http://www.cnblogs.com/xumenger ...

  3. OpenCV-paper detection & perspective transformation 相关资料

    经过一段时间的搜索,决定把搜过的资料都汇集在此,以免重复劳动,几乎来自stackoverflow OpenCV C++/Obj-C: Detecting a sheet of paper / Squa ...

  4. Solr入门之(6)配置文件solrconfig.xml

    solrconfig.xml包含了用于配置自身行为的绝大部分参数,其作用范围是当前core.该文件位于${solr_home}/solr/core1/conf/下. 参数列表概览: A.lib B.d ...

  5. MyEclipse 关闭鼠标悬停提示

    preference --> MyEclipse -->Files and Editors--> Common Editor Preference --> Hovers 把里面 ...

  6. PHP检测终端设备是平板、手机还是电脑

    <?php $ua = $_SERVER['HTTP_USER_AGENT']; function userAgent($ua){ $iphone = strstr(strtolower($ua ...

  7. [Linux][VMWare] 学习笔记之安装Linux系统-网络配置

    最近开始折腾Linux,在本机装了个VMWare和Centos,装完之后虚拟机里面的OS可以上网,但是使用SecureCRT连接不上虚拟机,开始折腾这个网络. vmware安装好以后,会自动添加两张网 ...

  8. 从github下载某个git库的4种方法

    转自:http://blog.csdn.net/feiniao1221/article/details/7516421 以gerrit-trigger-plugin为例,下面的链接都是从相应页面上直接 ...

  9. cocos2dx游戏开发——微信打飞机学习笔记(二)——游戏框架

    一.游戏的基本框架: WelcomeScene    ——>    GameScene   ——>   GameOverScene ||                           ...

  10. Linux学习笔记(3)Linux常用命令之文件处理命令

    Linux的命令格式一般为:命令 [-选项] [参数],如ls -la /etc,需要注意几点:1)个别命令使用不遵循此格式:2)当有多个选项时,可以写在一起:3)存在简化选项(-)与完整选项,如-a ...