连续两天学了一些numerical analysis的方法,昨天是学了一下三分,今天学了一下模拟退火。很早就听说了模拟退火在求费马点上的运用了,只知道一些大概,但是没有深入研究,碰到题目就卡壳了,现在算是补一下这种方法的思路。

模拟退火就是随机一些起点,然后定一个步长,每次在k个方向上去走这个步长,看下哪个方向最优,最优的话则留下来,然后步长*p,p就是控制的系数,然后如此重复。当然退火的含义就是有些时候我们会选择跳出当前的局部最优解,这个概率是预先设定的,在今天这题里貌似也不需要设定这样的概率,感觉有种水过去的感觉,贴一记代码

#pragma warning(disable:4996)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#define maxn 100
#define eps 1e-6
using namespace std; double x[maxn], y[maxn], z[maxn];
int n; double cal(double a, double b, double c)
{
double ans = 0;
for (int i = 0; i < n; i++){
ans += sqrt((x[i] - a)*(x[i] - a) + (y[i] - b)*(y[i] - b) + (z[i] - c)*(z[i] - c));
}
return ans;
} int main()
{
while (cin >> n)
{
for (int i = 0; i < n; i++){
scanf("%lf%lf%lf", x + i, y + i, z + i);
}
double curx, cury, curz;
double nxtx, nxty, nxtz;
curx = cury = curz = 0;
double cur = cal(curx, cury, curz);
double step = 1500;
while (step>eps){
double tmpx = -1, tmpy = -1, tmpz = -1; bool upd = false;
for (int i = -1; i <= 1; i++){
for (int j = -1; j <= 1; j++){
for (int k = -1; k <= 1; k++){
nxtx = curx + step*i;
nxty = cury + step*j;
nxtz = curz + step*k;
double nxt = cal(nxtx, nxty, nxtz);
if (nxt < cur){
tmpx = curx + step*i;
tmpy = cury + step*j;
tmpz = curz + step*k;
cur = nxt;
upd = true;
}
}
}
}
if (upd) {
curx = tmpx; cury = tmpy; curz = tmpz;
}
step *= 0.997;
}
printf("%.3lf %.3lf %.3lf\n", curx, cury, curz);
}
return 0;
}

ZOJ2928 Mathematical contest in modeling(模拟退火)的更多相关文章

  1. 计算机本科/硕士找offer的总结 节选

    在这样的目标定位下,我的求职历程从2006年10月8日开始,到2007年1月10日正式结束,一共持续了3个月的时间.整个过程可以分为三个阶段:第一阶段:2006年10月份 找工作刚刚开始的阶段,什么都 ...

  2. Preparation for MCM/ICM Writing

    Preparation for MCM/ICM Writing -- by Chance Zhang $1^{st}ed$ key words: MCM/ICM, format, phrases, t ...

  3. How do I learn mathematics for machine learning?

    https://www.quora.com/How-do-I-learn-mathematics-for-machine-learning   How do I learn mathematics f ...

  4. CFG的定义

    最近在CMU上NLP,好吧 对于见了很多年的CFG(Context-Free Grammar)发现又搞不懂是什么了 教材上写的是: mathematical system for modeling c ...

  5. (翻译)2016美国数学建模MCM E题(环境)翻译:我们朝向一个干旱的星球?

    PROBLEM E: Are we heading towards a thirsty planet? Will the world run out of clean water? According ...

  6. 【模拟退火】Petrozavodsk Winter Training Camp 2017 Day 1: Jagiellonian U Contest, Monday, January 30, 2017 Problem F. Factory

    让你在平面上取一个点,使得其到给定的所有点的距离和最小. 就是“费马点”. 模拟退火……日后学习一下,这是从网上扒的,先存下. #include<iostream> #include< ...

  7. 《A First Course in Mathematical Modeling》-chaper2-建模过程、比例性及几何相似性

    这一章节着重从整体的层面给出数学建模过程中一个泛式流程,它给出了在给现实模型建立数学模型的框架性思路,但是需要注意的是,虽然这里称其为一种“泛式”思路,但是在具体的问题的分析中,整个建模过程还是充满了 ...

  8. 《A First Course in Mathematical Modeling》-chaper1-差分方程建模

    从今天开始笔者将通过这个专栏可是对“数学建模”的学习.其实对于“数学建模”自身的内涵或者意义并不需要太多的阐释,下图简洁明了的阐释了数学建模的意义. 其实数学建模本身可以看成换一种角度去解读数学,将我 ...

  9. Competing in a data science contest without reading the data

    Competing in a data science contest without reading the data Machine learning competitions have beco ...

随机推荐

  1. SRF之页面

    页面呈现采用Razor模板   1.母模板说明 _Main.cshtml:基础母模板 _ListLayout.cshtml:列表页面 _EditDialog.cshtml:编辑对话框 _EditLay ...

  2. poj 1564 Sum It Up

    题目连接 http://poj.org/problem?id=1564 Sum It Up Description Given a specified total t and a list of n ...

  3. mac下的ssh自动登陆

    终端的ssh是标准的OpenSSH client 如果需要克隆会话功能,可以通过配置打开. $ cat .ssh/config Host * ControlMaster auto ControlPat ...

  4. exception -----> Typedefs & Classes

    #include <exception> Typedefs exception_ptr 一种类型,描述了一个指向异常的指针 terminate_handler 一种类型,描述了一个适合作为 ...

  5. [转]What’s Behind Ericsson’s OpenWebRTC Project?

    [转]What’s Behind Ericsson’s OpenWebRTC Project? http://www.tuicool.com/articles/z6rAVrJ Ericsson’s O ...

  6. hi3531播放1080p60f, 延迟越来越大的问题与解决办法

    问题 hi3531播放1080p60f, 延迟越来越大 左边屏幕是ffplay播放的,右边屏幕是3531播放的 数据是udp组播 mpegts, h264 12M码流 原因 经过测试发现: 解码器中缓 ...

  7. java提高篇-----详解java的四舍五入与保留位

    转载:http://blog.csdn.net/chenssy/article/details/12719811 四舍五入是我们小学的数学问题,这个问题对于我们程序猿来说就类似于1到10的加减乘除那么 ...

  8. 89C51单片机实现的流水灯

    /*******************************************Copyright:  2014.02.09.version1.0File name: led.cDescrip ...

  9. [shell基础]——sed命令

    关于sed sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓 ...

  10. (转)Python JSON序列化

    import json # dict to json d=dict(name="cui",age=20,score=88) print json.dumps(d) #list to ...