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 ...
随机推荐
- string::size_type类型
string::size_type类型 对于string中的size函数,size函数返回的是string对象的字符个数(长度),我们知道,对size()来说,返回一个int或者是一个unsigned ...
- HTML | video的封面平铺方法
<video style="object-fit:fill;"></video>
- shell定时统计Nginx下access.log的PV并发送给API保存到数据库
1,统计PV和IP 统计当天的PV(Page View) cat access.log | sed -n /`date "+%d\/%b\/%Y"`/p |wc -l 统计某一天的 ...
- PHP防止数字太大转化为科学计数法的方法
PHP当数字在20位或者20位以上时,会转化为科学计数法 例子: <?phpecho 11111111111111111111; ?> 解决方法可以使用php函数number_format ...
- php 算法(二分法)只适用于有序表,且限于顺序存储结构
function demo($array,$low,$high,$k){ if($low<=$high){//判断该数组是否存在 $mid = intval(($low+$high)/2 ); ...
- python--模块之sys与python解释器交互模块
作用:sys模块是与python解释器交互的一个接口.它提供了一系列有关python运行环境的变量和函数. 常用函数:import sys sys.argv #命令行参数list,第一个元素是程序本身 ...
- 《PHP发送邮件PHPMailer》系列分享专栏
<PHP发送邮件PHPMailer>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/201726.html 文章 PHPMailer ...
- java 优化版 用接口实现(输入两个数选择实现加减乘除运算)
//利用java接口实现计算器,实现加减乘除的功能 import java.util.Scanner; class Test { public static void main(String[] ar ...
- HCA数据下载
HCA data downloads HCA data downloads PeRl` 还记得去年看的时候还是什么都没有,今年已经有数据可以下载了.
- 推荐 的FPGA设计经验(1)组合逻辑优化
主要内容摘自Quartus prime Recommended Design Practices For optimal performance, reliability, and faster ti ...