poj 2420
来源:互联网 发布:大数据双创中心是什么 编辑:程序博客网 时间:2024/05/01 10:45
#include <iostream> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #include <math.h> #define N 1005 #define eps 1e-8 //搜索停止条件阀值 #define INF 1e99 #define delta 0.98 //温度下降速度 #define T 100 //初始温度 using namespace std; int dx[4] = {0, 0, -1, 1}; int dy[4] = {-1, 1, 0, 0}; //上下左右四个方向 struct Point { double x, y; }; Point 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 = 0; while(n--) ans += dist(p[n], t); return ans; } //其实我觉得这玩意儿根本不叫模拟退火 double Search(Point p[], int n) { Point s = p[0]; //随机初始化一个点开始搜索 double t = T; //初始化温度 double ans = INF; //初始答案值 while(t > eps) { bool flag = 1; while(flag) { flag = 0; for(int i = 0; i < 4; 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 = 1; } } } t *= delta; } return ans; } int main() { int n; while(scanf("%d", &n) != EOF) { for(int i = 0; i < n; i++) scanf("%lf %lf", &p[i].x, &p[i].y); printf("%.0lf\n", Search(p, n)); } return 0; }
0 0
- poj 2420
- poj 2420
- POJ - 2420
- poj 2420
- poj 2420
- 模拟退火 (poj 2420, poj 2069)
- POJ 2420解题报告
- POJ 2080/ZOJ 2420
- POJ 2420 模拟退火
- poj 2420 模拟退火
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- IT职业技能图谱(全套13张)
- 二叉树三种遍历方式的递归和循环实现
- HHU 欧洲杯(血泪。。。)
- 模板方法模式——以不变应万变
- NYOJ:奇怪的排序
- poj 2420
- css3 盒子类型
- Python |绝不乱入的靠谱书单
- Servlet API中的八种监听器接口
- ios 抛物线添加到购物车
- 树状数组( 单点修改/区间修改+区间求和+一维/二维)
- 191. Number of 1 Bits *
- Memcached 之 .NET(C#)实例分析
- 在Ubuntu14.04中安装Docker