POJ 2069 Super Star(计算几何の最小球包含+模拟退火)
Description
According to this theory, starts we are observing are
not independent objects, but only small portions of larger objects called super
stars. A super star is filled with invisible (or transparent) material, and only
a number of points inside or on its surface shine. These points are observed as
stars by us.
In order to verify this theory, Dr. Extreme wants to build
motion equations of super stars and to compare the solutions of these equations
with observed movements of stars. As the first step, he assumes that a super
star is sphere-shaped, and has the smallest possible radius such that the sphere
contains all given stars in or on it. This assumption makes it possible to
estimate the volume of a super star, and thus its mass (the density of the
invisible material is known).
You are asked to help Dr. Extreme by
writing a program which, given the locations of a number of stars, finds the
smallest sphere containing all of them in or on it. In this computation, you
should ignore the sizes of stars. In other words, a star should be regarded as a
point. You may assume the universe is a Euclidean space.
Input
set is given in the following format.
n
x1 y1 z1
x2 y2 z2
.
. .
xn yn zn
The first line of a data set contains an integer n,
which is the number of points. It satisfies the condition 4 <= n <= 30.
The location of n points are given by three-dimensional orthogonal
coordinates: (xi, yi, zi) (i = 1, ..., n). Three coordinates of a point appear
in a line, separated by a space character. Each value is given by a decimal
fraction, and is between 0.0 and 100.0 (both ends inclusive). Points are at
least 0.01 distant from each other.
The end of the input is indicated by
a line containing a zero.
Output
containing all given points should be printed, each in a separate line. The
printed values should have 5 digits after the decimal point. They may not have
an error greater than 0.00001.
#include <cstdio>
#include <cmath> const int MAXN = 50;
const double EPS = 1e-6; struct Point3D {
double x, y, z;
Point3D(double xx = 0, double yy = 0, double zz = 0):
x(xx), y(yy), z(zz) {}
}; Point3D operator - (const Point3D &a, const Point3D &b) {
return Point3D(a.x - b.x, a.y - b.y, a.z - b.z);
} double dist(const Point3D &a, const Point3D &b) {
Point3D c = a - b;
return sqrt(c.x * c.x + c.y * c.y + c.z * c.z);
} Point3D p[MAXN];
int n; void solve() {
Point3D s;
double delta = 100, ans = 1e20;
while(delta > EPS) {
int d = 0;
for(int i = 1; i < n; ++i)
if(dist(s, p[i]) > dist(s,p[d])) d = i;
double maxd = dist(s, p[d]);
if(ans > maxd) ans = maxd;
s.x += (p[d].x - s.x)/maxd*delta;
s.y += (p[d].y - s.y)/maxd*delta;
s.z += (p[d].z - s.z)/maxd*delta;
delta *= 0.98;
}
printf("%.5f\n", ans);
} int main() {
while(scanf("%d", &n) != EOF && n) {
for(int i = 0; i < n; ++i) scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z);
solve();
}
}
POJ 2069 Super Star(计算几何の最小球包含+模拟退火)的更多相关文章
- poj 2069 Super Star——模拟退火(收敛)
题目:http://poj.org/problem?id=2069 不是随机走,而是每次向最远的点逼近.而且也不是向该点逼近随意值,而是按那个比例:这样就总是接受,但答案还是要取min更新. 不知那个 ...
- poj 2069 Super Star —— 模拟退火
题目:http://poj.org/problem?id=2069 仍是随机地模拟退火,然而却WA了: 看看网上的题解,都是另一种做法——向距离最远的点靠近: 于是也改成那样,竟然真的A了...感觉这 ...
- POJ 2069 Super Star
模拟退火. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...
- poj 2069 Super Star 模拟退火
题目大意: 给定三位空间上的n(\(n \leq 30\))个点,求最小的球覆盖掉所有的点. 题解: 貌似我们可以用类似于二维平面中的随机增量法瞎搞一下 但是我不会怎么搞 所以我们模拟退火就好了啊QA ...
- 【POJ】2069.Super Star
题解 求一个最小的半径的球,包括三维平面上所有的点,输出半径 随机移动球心,半径即为距离最远的点,移动的方式是向离的最远的那个点移动一点,之后模拟退火就好 代码 #include <iostre ...
- Super Star(最小球覆盖)
Super Star http://poj.org/problem?id=2069 Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- POJ 2069 模拟退火算法
Super Star Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6422 Accepted: 1591 Spec ...
- 三分 POJ 2420 A Star not a Tree?
题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...
- POJ 2420 A Star not a Tree? (计算几何-费马点)
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3435 Accepted: 172 ...
随机推荐
- JAVA基础之控制台输入输出
---恢复内容开始--- 输入需要用scanner机制 代码: 启用scanner机制 Scanner input = new Scanner(System.in); //String x= inpu ...
- Windows远程常见问题
1.window2003远程桌面“已达最大连接数”解决:1)mstsc /v:(此处为服务器IP) /console 任务管理器注销已断开用户 mstsc /v:192.168.4.3 /cons ...
- js中定时器使用方法经验总结
前言,最近在做一个音频播放项目的时候,碰到播放时间精度的问题,捣鼓了几天,最终巧妙的运用定时器去降低了错误发生频率 正题,下面是对定时器的使用总结,如有错误之处,请读者加以纠正. 延迟执行(1次) s ...
- 也说java虚拟机
学习java的人如果不了解java虚拟机,那真是白学了. java为什么可以跨平台,就是因为虚拟机的作用,java虚拟机就相当于一个计算机,它有自己的内存结构,当java程序 ...
- sass的嵌套
sass的嵌套包括两种: 1.选择器的嵌套.(最常用到) 指的是在一个选择器中嵌套另一个选择器来实现继承,从而增强了sass文件的结构性和可读性. 在选择器嵌套中,可以使用&表示父元素选择器 ...
- Throwable类
1.Throwable是所有异常的基类(父类),两个子类Error和Exception ①Error:java运行时系统的内部错误或资源耗尽错误,应用程序不应该抛出这种类型的对象,一旦发生这种异常除了 ...
- hadoop生态搭建(3节点)-10.spark配置
# https://www.scala-lang.org/download/2.12.4.html# ================================================= ...
- Gitlab 自动构建心得
上面是简单接受一下gitlab ci的工作原理 GitLab-CI 这个是一套配合GitLab使用的持续集成系统,是GitLab自带的,也就是你装GitLab的那台服务器上就带有的.无需多考虑..gi ...
- 『Python基础-12』各种推导式(列表推导式、字典推导式、集合推导式)
# 『Python基础-12』各种推导式(列表推导式.字典推导式.集合推导式) 推导式comprehensions(又称解析式),是Python的一种独有特性.推导式是可以从一个数据序列构建另一个新的 ...
- Python学习知识库
2017年10月16日 1. too broad exception clause 捕获的异常过于宽泛了,没有针对性,应该指定精确的异常类型场景: def check_data_type(column ...