UVA 10228 - Star not a Tree?(模拟退火)
来源:互联网 发布:初开淘宝店卖什么好 编辑:程序博客网 时间:2024/06/04 21:54
UVA 10228 - Star not a Tree?
题目链接
题意:给定一些点,费马点(到这些点距离和最短),输出距离和
思路:模拟退火去搞,初始温度1W步,降温系数设为0.83,然后每次找周围4个方向,做10次保证答案准确
代码:
#include <cstdio>#include <cstring>#include <cmath>#include <ctime>#include <cstdlib>#include <algorithm>using namespace std;const int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};const int N = 105;const double eps = 1e-3;int t, n;struct Point { double x, y, d; Point() {} Point(double a, double b) {x = a; y = b; }} p[N];double getdis(Point P) { double ans = 0; for (int i = 0; i < n; i++) {double dx = p[i].x - P.x;double dy = p[i].y - P.y;ans += sqrt(dx * dx + dy * dy); } return ans;}double gao() { int cnt = 10; double ans = 1e20, r = 0.83; srand(time(NULL)); while (cnt--) {double step = 1e4;Point now = Point(rand() % 10001, rand() % 10001);now.d = getdis(now);while (step > eps) { Point next; for (int i = 0; i < 4; i++) {next = Point(now.x + step * d[i][0], now.y + step * d[i][1]);next.d = getdis(next);if (next.d < now.d) now = next; } step *= r; ans = min(ans, now.d);} } return ans;}int main() { scanf("%d", &t); while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);printf("%.0lf\n", gao());if (t) printf("\n"); } return 0;}
1 0
- UVA 10228 - Star not a Tree?(模拟退火)
- uva 10228 - Star not a Tree?(模拟退火)
- A Star not a Tree? 模拟退火
- poj2420A 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】【P2420】【A Star not a Tree?】【题解】【模拟退火】
- 模拟退火算法A Star not a Tree?(poj2420)
- 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?(模拟退火算法)
- UVA - 11983 Weird Advertisement (线段树求并面积)
- Hibernate单向多对一级联删除引发的问题
- HDU2544,最短路
- V7 jar
- 【RPi树莓派使用指南】GPIO驱动方法
- UVA 10228 - Star not a Tree?(模拟退火)
- Nested Classes,Static Classes,Non-static Classes,Inner Classes,Local Classes,Anonymous Classes
- Android:实现手势滑动的事件处理方法
- HDU 4883 Best Coder Round 2 TIANKENG’s restaurant 题解
- JavaScript中跨域调用Flash的方法
- hdu 3473划分树~~求中间值
- Til the Cows Come Home poj 2387 c++
- repair filesystem#
- NYOJ 题目42 一笔画问题 (欧拉连通图+并查集)