题目链接:http://poj.org/problem?id=2420

题意:给n个点,找出一个点,使这个点到其他所有点的距离之和最小,也就是求费马点。

参考链接:http://www.cnblogs.com/heaad/archive/2010/12/20/1911614.html

这一篇文章写的很好,我这个小白都有一点小明白了。

记一下笔记:

模拟退火: 就是在一定范围内接受一些不是最优的解,来跳出局部最优,靠近整体最优。

贴一下伪代码:

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<deque>
#include<functional>
#include<iterator>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath> using namespace std; #define N 1005
#define eps 1e-8
#define INF 1e99
#define delta 0.98
#define T 100 int dx[] = {,,-,};
int dy[] = {-,,,}; struct Point
{
double x,y;
} p[N]; double dist (Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double GetSum(Point p[],int n,Point t)
{
double ans = ;
while(n--)
{
ans+=dist(p[n],t);
}
return ans;
} double Search(Point p[],int n)
{
Point s = p[];
double t = T;
double ans = INF;
while(t>eps)
{
bool flag = ;
while(flag)
{
flag = ;
for(int i=; i<; i++)
{
Point z;
z.x = s.x + dx[i]*t;
z.y = s.y + dy[i]*t;
double tp = GetSum(p,n,z);
if(ans>tp)
{
ans = tp;
s = z;
flag = ;
}
}
}
t*=delta;
}
return ans;
} int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=; i<n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
printf("%.0lf\n",Search(p,n));
}
return ;
}

poj 2420,模拟退火算法,费马点的更多相关文章

  1. poj 2420(模拟退火)

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

  2. POJ 2069 模拟退火算法

    Super Star Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6422   Accepted: 1591   Spec ...

  3. poj 2420 模拟退火法基础

    /* 题意:给n个电脑,求一个点到这n个电脑的距离和最小. 模拟退火法:和poj1379的方法类似 因为坐标范围是0-10000 不妨把它看成是10000*10000的正方形来做 */ #includ ...

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

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

  5. poj 2420 A Star not a Tree? —— 模拟退火

    题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...

  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 SETI 高斯消元 + 费马小定理

    http://poj.org/problem?id=2065 题目是要求 如果str[i] = '*'那就是等于0 求这n条方程在%p下的解. 我看了网上的题解说是高斯消元 + 扩展欧几里德. 然后我 ...

  8. poj 1845 【数论:逆元,二分(乘法),拓展欧几里得,费马小定理】

    POJ 1845 题意不说了,网上一大堆.此题做了一天,必须要整理一下了. 刚开始用费马小定理做,WA.(poj敢说我代码WA???)(以下代码其实都不严谨,按照数据要求A是可以等于0的,那么结果自然 ...

  9. poj 3734 Blocks 快速幂+费马小定理+组合数学

    题目链接 题意:有一排砖,可以染红蓝绿黄四种不同的颜色,要求红和绿两种颜色砖的个数都是偶数,问一共有多少种方案,结果对10007取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友 ...

随机推荐

  1. HDU 4718 The LCIS on the Tree(树链剖分)

    Problem Description For a sequence S1, S2, ... , SN, and a pair of integers (i, j), if 1 <= i < ...

  2. php 迭代器

    迭代器(Iterator)模式,又叫做游标(Cursor)模式.GOF给出的定义为:提供一种方法访问一个容器(container)对象中各个元素,而又不需暴露该对象的内部细节. 百度百科: http: ...

  3. mongo快速翻页方法(转载)

    翻阅数据是MongoDB最常见的操作之一.一个典型的场景是需要在你的用户界面中显示你的结果.如果你是批量处理的数据,同样重要的是要让你的分页策略正确,以便你的数据处理可以规模化. 接下来,让我们通过一 ...

  4. Jquery文档接口遍历

    // children():获取所有子元素 <%@ page language="java" contentType="text/html; charset=utf ...

  5. jquery 下拉菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Revit 二次开发 (二) 倾斜的板

    在Revit二次开发过程中,建立一个倾斜的板是可以通过如下方法进行的: // // 摘要: // Creates a slab within the project with the given ho ...

  7. FastJson之有道翻译

    在AndroidMainifast.xml中加入相应的访问权限 <uses-permission android:name="android.permission.INTERNET&q ...

  8. phaser运用中,dota战术板

    首发:个人博客,更新&纠错&回复 还是没想好用phaser做个啥小游戏好,以每年春节打dota的这两伙人为基础是肯定的,但游戏具体咋做还没头绪. 暂时试着做了个卡通版dota地图,可以 ...

  9. IOC依赖注入简单实例

    转自:http://hi.baidu.com/xyz136299110/item/a32be4269e9d0c55c38d59e6 相信大家看过相当多的IOC依赖注入的例子. 但大家在没有明白原理的情 ...

  10. (顺序表的应用5.4.2)POJ 1591 M*A*S*H(约瑟夫环问题的变形——变换步长值)

    /* * POJ_1591_2.cpp * * Created on: 2013年10月31日 * Author: Administrator */ #include <iostream> ...