【POJ 2420】A Star not a Tree?
2017-03-19 19:04
316 查看
其实就是找一个费马点。
我感觉这玩意儿根本不叫模拟退火啊,这个退火的概率都没出现,唯一有点退火的就是搜索的范围逐渐减小。
每次朝着上下左右的更优方向走,暴力的步长为1,模拟退火的步长就是当前温度,也就是说搜索的范围会越来越小,也越接近费马点。
坑爹啊竟然精度这么点,一开始double强制转int死活过不了,后来才知道要四舍五入。。。
我感觉这玩意儿根本不叫模拟退火啊,这个退火的概率都没出现,唯一有点退火的就是搜索的范围逐渐减小。
每次朝着上下左右的更优方向走,暴力的步长为1,模拟退火的步长就是当前温度,也就是说搜索的范围会越来越小,也越接近费马点。
坑爹啊竟然精度这么点,一开始double强制转int死活过不了,后来才知道要四舍五入。。。
#include<cmath> #include<cstdio> #include<vector> #include<queue> #include<cstring> #include<iomanip> #include<stdlib.h> #include<iostream> #include<algorithm> #define ll long long #define inf 1000000000 #define mod 1000000007 #define N 200 #define fo(i,a,b) for(i=a;i<=b;i++) #define fd(i,a,b) for(i=a;i>=b;i--) using namespace std; int n,i,j,T; int cnt; double x ,y ; double ans,px,py,nx,ny; const int max_rand = 2333333; void calc(double qx,double qy,double &s) { int i; s = 0; fo(i,1,n) s += hypot(x[i]-qx,y[i]-qy); } double solve() { int i; double res,dis; const double max_tmp = 10000; const double dec = 0.5; double tmp = max_tmp; px = x[1]; py = y[1]; calc(px,py,res); while (tmp > 0.02) { fo(i,-1,1) fo(j,-1,1) { nx = px + tmp * i; ny = py + tmp * j; calc(nx,ny,dis); //if (accept(dis2-dis1,tmp)) if (dis < res) px = nx,py = ny,res = dis; } tmp *= dec; } return res; } int main() { srand(233333); scanf("%d",&n); fo(i,1,n) scanf("%lf%lf",&x[i],&y[i]); printf("%d\n",(int)(solve()+0.5)); return 0; }
相关文章推荐
- POJ 2420 A Star not a Tree?
- poj 2420 A Star not a Tree?(贪心+求多边形费马点)
- poj 2420 A Star not a Tree?(模拟退火)
- POJ 2420 A Star not a Tree?(随机变步长贪心)
- [POJ 2420] A Star not a Tree?
- POJ 2420 A Star not a Tree? 费马点,模拟退火
- [poj 2420]A Star not a Tree?[模拟退火]
- poj 2420 A Star not a Tree?(模拟退火)
- POJ2420——A Star not a Tree?
- poj 2420 A Star not a Tree?
- poj 2420 A Star not a Tree? 模拟退火
- POJ 2420 A Star not a Tree? (模拟退火)
- POJ 2420 A Star not a Tree?(模拟退火)
- poj 2420 A Star not a Tree?(模拟退火求费马点)
- POJ 2420 A Star not a Tree?【爬山法】
- poj 2420 A Star not a Tree?
- 【POJ】【2420】A Star not a Tree?
- POJ 2420 A Star not a Tree? (计算几何-费马点)
- POJ 2420 A Star not a Tree?
- poj 2420 A Star not a Tree?