博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2420 A Star not a Tree? 模拟退火
阅读量:4530 次
发布时间:2019-06-08

本文共 1154 字,大约阅读时间需要 3 分钟。

题目大意:

给定n个点,求一个点,使其到这n个点的距离最小.(\(n \leq 100\))

题解

模拟退火上

#include 
#include
#include
#include
using namespace std;typedef long long ll;inline void read(int &x){ x=0;char ch;bool flag = false; while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true; while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;}inline int cat_max(const int &a,const int &b){return a>b ? a:b;}inline int cat_min(const int &a,const int &b){return a
eps){ flag = true; while(flag){ flag = false; for(int i=1;i<=4;++i){ x = pi*2.0*ran(); Point nx(nw.x+T*cos(x),nw.y+T*sin(x)); de = f(nw) - f(nx); if(de > 0 || exp(de/T) > ran()){ nw = nx;flag = true; } T *= det; } } } T = eps; for(int i=1;i<=1000;++i){ x = pi*2.0*ran(); f(Point(ans.x+T*cos(x)*ran(),ans.y+T*sin(x)*ran())); } printf("%.0lf\n",ans_min); getchar();getchar(); return 0;}

转载于:https://www.cnblogs.com/Skyminer/p/6438260.html

你可能感兴趣的文章
LeetCode: 103_Binary Tree Zigzag Level Order Traversal | 二叉树Zigzag层次遍历 | Medium
查看>>
【记忆化搜索】[NOIP-2017--普及组] -- 棋盘
查看>>
MyBatis_[tp_48]_动态sql_内置参数_parameter&_databaseId
查看>>
Storm 集群安装
查看>>
使用情感分析技术做营销
查看>>
基于Token的WEB后台认证机制
查看>>
高级树状数组——区间修改区间查询、二维树状数组
查看>>
创造者模式
查看>>
element-ui 上传图片 后清空 图片 显示
查看>>
试玩汇编语言 1:环境搭建
查看>>
golang的的模板引擎之pongo2
查看>>
git中Please enter a commit message to explain why this merge is necessary
查看>>
Backbone.js 资源搜集
查看>>
CSS优先级问题以及jQuery中的.eq()遍历方法和:eq()选择器的差别
查看>>
Remote desktop connect to Opensuse 11 using xmanager on Windows 7
查看>>
使用Navicat连接oracle时出现unsupported server character set ZHS16GBK的解决之道
查看>>
tensorflow Sigmoid 应用
查看>>
Maven学习(七)仓库
查看>>
Valid Palindrome
查看>>
609. Find Duplicate File in System
查看>>