ZOJ2928 Mathematical contest in modeling(模拟退火)
连续两天学了一些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(模拟退火)的更多相关文章
- 计算机本科/硕士找offer的总结 节选
在这样的目标定位下,我的求职历程从2006年10月8日开始,到2007年1月10日正式结束,一共持续了3个月的时间.整个过程可以分为三个阶段:第一阶段:2006年10月份 找工作刚刚开始的阶段,什么都 ...
- Preparation for MCM/ICM Writing
Preparation for MCM/ICM Writing -- by Chance Zhang $1^{st}ed$ key words: MCM/ICM, format, phrases, t ...
- 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 ...
- CFG的定义
最近在CMU上NLP,好吧 对于见了很多年的CFG(Context-Free Grammar)发现又搞不懂是什么了 教材上写的是: mathematical system for modeling c ...
- (翻译)2016美国数学建模MCM E题(环境)翻译:我们朝向一个干旱的星球?
PROBLEM E: Are we heading towards a thirsty planet? Will the world run out of clean water? According ...
- 【模拟退火】Petrozavodsk Winter Training Camp 2017 Day 1: Jagiellonian U Contest, Monday, January 30, 2017 Problem F. Factory
让你在平面上取一个点,使得其到给定的所有点的距离和最小. 就是“费马点”. 模拟退火……日后学习一下,这是从网上扒的,先存下. #include<iostream> #include< ...
- 《A First Course in Mathematical Modeling》-chaper2-建模过程、比例性及几何相似性
这一章节着重从整体的层面给出数学建模过程中一个泛式流程,它给出了在给现实模型建立数学模型的框架性思路,但是需要注意的是,虽然这里称其为一种“泛式”思路,但是在具体的问题的分析中,整个建模过程还是充满了 ...
- 《A First Course in Mathematical Modeling》-chaper1-差分方程建模
从今天开始笔者将通过这个专栏可是对“数学建模”的学习.其实对于“数学建模”自身的内涵或者意义并不需要太多的阐释,下图简洁明了的阐释了数学建模的意义. 其实数学建模本身可以看成换一种角度去解读数学,将我 ...
- 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 ...
随机推荐
- ios view的frame和bounds之区别(位置和大小)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- NOJ1066-堆排序
堆排序 时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte总提交 : 414 测试通过 : 220 比 ...
- 点击TableView中某行进入下一级界面(Swift)
TableView这个控件在iOS的开发中非常的常见,他可以较好的展示一个层级结构.这里主要介绍,在点击某个条目的时候,如何进行跳转的下一个界面.以下是官方的关于这个跳转如何去实现,和如何去传递数据的 ...
- 将获得到的json赋值到下拉框
$(function () { $.getJSON('handler/addEmployees.ashx', function (json) { alert(json.length); //遍历赋值 ...
- 【转载】about slack
About Slack slack is the difference b/w the REQUIRED TIME and the ARRIVAL TIME. 1.WHAT IS SLACK WITH ...
- html readme
取html页面高度 document.documentElement.scrollHeight在IE和Chrome下,可以正常取到合适的全文高度,但是firefox下取到的则过高: 用document ...
- 查看BADI有哪些实现
TCODE:SE18
- 【AFNetworking】AFNetworking源码阅读(一)
1. 前言 2. iOS Example代码结构 3.AFNetworkActivityIndicatorManager 4. UIRefreshControl+AFNetworking 5. AFN ...
- java 判断两个数是否异号
java 整型int占4个字节32位,两个数异或后移动31位判断结果,如果是1则异号,如果是0则同号 public class ShowEnviromentViarible { public stat ...
- Linux 前台 和 后台进程 说明
一. 有关进程的几种常用方法 1.1 & 符号 在命令后面加上一个 & 符号,表示该命令放在后台执行,如: [oracle@singledb ~]$ crontab -l 20 17 ...