Super Star(最小球覆盖)
Super Star
http://poj.org/problem?id=2069
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 6486 | Accepted: 1603 | Special Judge | ||
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
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
Sample Input
4
10.00000 10.00000 10.00000
20.00000 10.00000 10.00000
20.00000 20.00000 10.00000
10.00000 20.00000 10.00000
4
10.00000 10.00000 10.00000
10.00000 50.00000 50.00000
50.00000 10.00000 50.00000
50.00000 50.00000 10.00000
0
Sample Output
7.07107
34.64102
最小球覆盖模板题,先任意选取一个点,然后找到一个离它最远的点,不断逼近
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std; struct Point{
double x,y,z;
}p[]; double dist(Point a,Point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
} double ac(int n){
double ans=1e9;
Point tmp;
tmp.x=tmp.y=tmp.z=;;
int s=;
double step=;
double esp=0.0000001;
while(step>esp){
for(int i=;i<=n;i++){
if(dist(tmp,p[s])<dist(tmp,p[i])) s=i;
}
double Dist=dist(tmp,p[s]);
ans=min(ans,Dist);
tmp.x+=(p[s].x-tmp.x)/Dist*step;
tmp.y+=(p[s].y-tmp.y)/Dist*step;
tmp.z+=(p[s].z-tmp.z)/Dist*step;
step*=0.99;
}
return ans;
} int main(){
int n;
while(~scanf("%d",&n)){
if(!n) break;
for(int i=;i<=n;i++){
scanf("%lf %lf %lf",&p[i].x,&p[i].y,&p[i].z);
}
double ans=ac(n);
printf("%.5f\n",ans);
}
}
Super Star(最小球覆盖)的更多相关文章
- POJ 2069 Super Star(计算几何の最小球包含+模拟退火)
Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...
- D.Country Meow 最小球覆盖 三分套三分套三分 && 模拟退火
// 2019.10.3 // 练习题:2018 ICPC 南京现场赛 D Country Meow 题目大意 给定空间内 N 个点,求某个点到 N 个点的距离最大值的最小值. 思路 非常裸的最小 ...
- POJ 最小球覆盖 模拟退火
最小球覆盖:用半径最小的球去覆盖所有点. 纯粹的退火算法,是搞不定的,精度不够,不然就会TLE,根本跑不出答案来. 任取一点为球心,然后一点点靠近最远点.其实这才是最主要的. 因为:4个点确定一个球, ...
- POJ2069 最小球覆盖 几何法和退火法
对这种问题不熟悉的读者 可以先去看一看最小圆覆盖的问题 ZOJ1450 现在我们来看最小球覆盖问题POJ2069 题目很裸,给30个点 求能覆盖所有点的最小球的半径. 先给出以下几个事实: 1.对于一 ...
- 最小球覆盖——模拟退火&&三分套三分套三分
题目 给出 $N(1 \leq N \leq 100)$ 个点的坐标 $x_i,y_i,z_i$($-100000 \leq x_i,y_i,z_i \leq 100000$),求包围全部点的最小的球 ...
- 使用super调用被子类覆盖的父类方法
1.没有super方法 /* * 子类方法覆盖父类方法,用super方法可以调用父类被覆盖的方法 */ class fruit{ public fruit() { System.out.println ...
- perl 使用SUPER类来访问覆盖的方法
有时候,你希望一个衍生类的方法表现得象基类中的某些方法的封装器 这就是 SUPER 伪类提供便利的地方.它令你能够调用一个覆盖了的基类方法,而不用声明 是哪个类定义了该方 法.(注:不要把这个和第十一 ...
- Super不要在Super构造器中调用覆盖方法
import java.util.Date; public class Super{ public Super(){ System."); overrideMe(); System.&quo ...
- 【模拟退火】poj2069 Super Star
题意:让你求空间内n个点的最小覆盖球. 模拟退火随机走的时候主要有这几种走法:①随机旋转角度. ②直接不随机,往最远的点的方向走,仅仅在尝试接受解的时候用概率.(最小圆/球覆盖时常用) ③往所有点的方 ...
随机推荐
- XStream和Dom4j的区别
对于搞技术的人来说,xml文件的处理应该并不陌生吧,先总述下,个人感觉XStream在处理XML文件和JavaBean对象互转时比较好,dom4j对常用的xml配置文件操作比较好点:首先,Dom4j ...
- TensorFlow函数:tf.FIFOQueue队列
转载:https://blog.csdn.net/akadiao/article/details/78552037 tf.FIFOQueue tf.FIFOQueue继承基类QueueBase. Qu ...
- Web 过滤器参数设置问题
问题描述: 在代码定义了3个过滤器,分别为filter1,filter2,filter3,过滤的Servlet范围分别是"/*","/Servlet1",&qu ...
- django从请求到响应的过程深入讲解
django启动 我们在启动一个django项目的时候,无论你是在命令行执行还是在pycharm直接点击运行,其实都是执行'runserver'的操作,而ruserver是使用django自带的的we ...
- 关于raid5的一系列问题
前几天我的一个同事在对计划采购的存储进行测试,期间聊到了raid5的话题,我和他的意见产生了分歧.他的说法是raid5不能挂太多盘是因为如果挂太多盘写惩罚会非常严重导致性能下降.而我的观点则是对于ra ...
- 从最大似然函数 到 EM算法详解
极大似然算法 本来打算把别人讲的好的博文放在上面的,但是感觉那个适合看着玩,我看过之后感觉懂了,然后实际应用就不会了.... MLP其实就是用来求模型参数的,核心就是“模型已知,求取参数”,模型的意思 ...
- 0_Simple__simpleMPI
MPI 的简单使用 ▶ 源代码.主机根结点生成随机数组,发布副本到各结点(例子用孩子使用了一个结点),分别使用 GPU 求平方根并求和,然后根结点使用 MPI 回收各节点的计算结果,规约求和后除以数组 ...
- HTML5 Canvas ( 线段端点的样式 ) lineCap
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- NPOI操作word文档1
1.首先进行XWPFDocument类的实例化,该类的实例对应一个word文档 XWPFDocument MyDoc = new XWPFDocument(); 2.设置页面的大小 CT_SectPr ...
- Simple2D-19(音乐播放器)播放器的源码实现
使用 BASS 和 ImGui 实现音乐播放器 MusicPlayer. 将播放器和一个文件夹关联起来,程序刚开始运行的时候就从该文件夹加载所有音频文件.而文件夹的路径则保存在配置文件中,所以程序的第 ...