• 最小圆覆盖:

HYSBZ 1337 最小圆覆盖

给出平面上N个点,N<=10^5.请求出一个半径最小的圆覆盖住所有的点

Input

第一行给出数字N,现在N行,每行两个实数x,y表示其坐标.

Output

输出最小半径,输出保留三位小数.

Sample Input

4 1 0 0 1 0 -1 -1 0

Sample Output

1.000

AC代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long lt;
#define eps 1e-6
#define sqr(x) ((x)*(x))const int maxn=1000010;
int n;
struct point{double x,y;
}p[maxn],O;
double R;//半径 double getd(point a,point b){ //求直径 return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
point getO(point p1,point p2,point p3) { //求圆心 point res;double a=p2.x-p1.x;double b=p2.y-p1.y;double c=p3.x-p2.x;double d=p3.y-p2.y;double e=sqr(p2.x)+sqr(p2.y)-sqr(p1.x)-sqr(p1.y);double f=sqr(p3.x)+sqr(p3.y)-sqr(p2.x)-sqr(p2.y);res.x=(f*b-e*d)/(c*b-a*d)/2.0; res.y=(a*f-e*c)/(a*d-b*c)/2.0;return res;
}
void mincir() {O=p[1]; R=0;for(int i=1;i<=n;++i){if(getd(p[i],O)-R>eps) { //不在圆内 O=p[i]; R=0;for(int j=1;j<i;j++) { if(getd(p[j],O)-R>eps) {//不在圆内 O=(point){(p[i].x+p[j].x)/2.0,(p[i].y+p[j].y)/2.0};R=getd(p[i],p[j])/2.0;for(int k=1;k<j;++k)if(getd(p[k],O)-R>eps) {//不在圆内 O=getO(p[i],p[j],p[k]);  //外接圆 R=getd(p[i],O);}}} }}
} int main()
{cin>>n;for(int i=1;i<=n;++i)scanf("%lf%lf",&p[i].x,&p[i].y);random_shuffle(p+1,p+1+n);// random_shuffle()随机打乱函数 首指针 尾指针 mincir();printf("%.3f",R);return 0;
}

剩下几题都套这个板子改一下输入输出稳过

HDU 3007 Buried memory

HYSBZ 1336 Alien最小圆覆盖

HYSBZ 2823 信号塔

  • 最小球覆盖:

POJ 2069  Super Star

During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors or singers. It is a revolutionary theory in astronomy.
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

The input consists of multiple data sets. Each data 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

For each data set, the radius of the smallest sphere 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.

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<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-5;
struct POINT{double x,y,z;
}p[110],op;//N个点
int 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)+(a.z-b.z)*(a.z-b.z));
}
double solve(){double ret,delta=100.0;//温度double maxDis,tempDis;int i,id;while(delta>eps){id=0;maxDis=dist(op,p[id]);for(i=1;i<n;i++){tempDis=dist(op,p[i]);if(tempDis>maxDis){maxDis=tempDis;id=i;}}ret=maxDis;op.x+=(p[id].x-op.x)/maxDis*delta;op.y+=(p[id].y-op.y)/maxDis*delta;op.z+=(p[id].z-op.z)/maxDis*delta;delta*=0.98;}return ret;//最小球半径
}
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);}printf("%.5f\n", solve());}return 0;
}

Problem D. Country Meow

In the 24th century, there is a country somewhere in the universe, namely Country Meow. Due to advancedtechnology, people can easily travel in the 3-dimensional space.There areNcities in Country Meow. Thei-th city is located at(xi, yi, zi)in Cartesian coordinate.Due to the increasing threat from Country Woof, the president decided to build a new combatantcommand, so that troops in different cities can easily communicate. Hence, the Euclidean distance betweenthe combatant command and any city should be minimized.Your task is to calculate the minimum Euclidean distance between the combatant command and the farthest city.

Input

The first line contains an integerN(1≤N≤100).The followingNlines describe thei-th city located.Each line contains three integersxi, yi, zi(−100000≤xi, yi, zi≤100000).

Output

Print a real number — the minimum Euclidean distance between the combatant command and the farthestcity. Your answer is considered correct if its absolute or relative error does not exceed10−3. Formally, letyour answer bea, and the jury’s answer beb. Your answer is considered correct if|a−b|max(1,|b|)≤10−3.Examplesstandard inputstandard output30 0 03 0 00 4 02.50000059025210340 0 01 0 00 1 00 0 10.816496631812619

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-8;
struct point3D
{double x,y,z;
} data[105];
int n;
double dis(point3D a,point3D 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 solve()
{double step=10000,ans=1e30,mt;point3D z;z.x=z.y=z.z=0;int s=0;while(step>eps){for(int i=0; i<n; i++)if(dis(z,data[s])<dis(z,data[i])) s=i;mt=dis(z,data[s]);ans=min(ans,mt);z.x+=(data[s].x-z.x)/mt*step;z.y+=(data[s].y-z.y)/mt*step;z.z+=(data[s].z-z.z)/mt*step;step*=0.98;}return ans;
}
int main()
{double ans;while(scanf("%d",&n)!=EOF){for(int i=0; i<n; i++)scanf("%lf%lf%lf",&data[i].x,&data[i].y,&data[i].z);ans=solve();printf("%.7f\n",ans);}return 0;
}

最小球覆盖最小圆覆盖 题目总结相关推荐

  1. matlab模拟退火最小球覆盖,最小圆覆盖最小球覆盖 (增量法和模拟退火法)

    这种题几乎一套板子走天下. 昨天做最小圆覆盖用的都是增量法,压根没看过退火模拟法,因为退火模拟法并不是很稳定.今天看最小球覆盖时发现用到了退火模拟法,于是看了看最小圆覆盖的退火模拟法,用退火板子提交直 ...

  2. POJ 2069最小球覆盖 HDU3007最小圆覆盖【模拟淬火算法】

    POJ 2069最小球覆盖 1.给定N个三维点,要求覆盖这些点的最小球半径: 2.采用模拟淬火算法,随机选取一个点作为初始解,然后不断向当前最远的点靠近: 3.这是一个不断调整的过程,对应模拟淬火算法 ...

  3. 随机增量法:bzoj 1336 bzoj 1337 最小圆覆盖

    1337: 最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1170  Solved: 573 [Submit][Status][Discus ...

  4. HDU2215(最小圆覆盖问题)

    题意:就是求最小圆覆盖问题 方法一: #include<iostream> #include<algorithm> #include<cmath> #include ...

  5. 【hdoj】3007 Buried memory 【计算几何--最小圆覆盖】

    传送门:Buried memory 苍天饶过谁,第三次在hdoj上 交计算几何的题了,没一次是AC的. ┭┮﹏┭┮都是模板题啊,我都是抄板子的啊,为什么会这样,我怎么这么菜. 题意: 求最小圆覆盖 的 ...

  6. hdu 2215(最小圆覆盖)

    解题思路:最小圆覆盖,注意由于树也有半径,所以要加上树的半径0.5 #include<iostream> #include<cmath> #include<cstdio& ...

  7. ZOJ - 1450 Minimal Circle HDU - 3007 Buried memory 最小圆覆盖模板 【随机函数】【增量法】

    题意 给N个点,求最小的圆将这N个点全部覆盖,输出圆心坐标和半径 分析 最小的圆肯定落在三个点上,因此暴力枚举圆上的三个点即可,点增量算法O(n ^ 3),加入随机化,平均复杂度可以降到O(n^2) ...

  8. P1742 最小圆覆盖

    P1742 最小圆覆盖 题意: 给出N个点,让你画一个最小的包含所有点的圆. 题解: 先说结论: 最优解的圆一定是在以某两个点连线为直径的圆 或者 某三个点组成的三角形的外接圆 初始化将某个圆心定为第 ...

  9. ZOJ 1450 Minimal Circle 点集的最小圆覆盖

    From: http://blog.csdn.net/zmx354/article/details/17076267 给定一个点集,求出能覆盖点集内所有点的半径最小的圆.包含点在圆上的情况.个人感觉算 ...

最新文章

  1. php中mvc代表什么意思,php mvc是什么意思?
  2. 将内存单元中小写字符改成大写字符
  3. boost::contract模块实现customer and manager的测试程序
  4. 慢性肾脏病蛋白营养治疗专家共识
  5. pyecharts怎么绘制散点图_PyeCharts绘制各种图形
  6. CSS垂直居中,你会多少种写法?
  7. centos7的启动过程
  8. 【模块】ESP32连接PS4手柄
  9. Python+OpenCV对证件照换底
  10. 4大领域、33篇课题成果,2021阿里研究生态报告集来了
  11. 在线办公的前浪与后浪:输出工具到输出能力
  12. coreseek-4.1-win32版本下windows安装记录
  13. vue + element 使用 iframe
  14. 华数机器人编程语言_华数机器人:以自主创新为引领,深耕细分领域
  15. java实现数字黑洞
  16. Hive HWI 安装及配置
  17. 政考网:省考上岸,2021国考有希望吗?
  18. 湖南附中模拟day1 金坷垃
  19. vue 文件目录详解
  20. 恶意代码分析-工具收集

热门文章

  1. 分布式中间件之Dubbo详解
  2. python:计算索引的类算法(附完整源码)
  3. 小伙子利用c++实现LOL无限视距并免费送上源码,网友:真香!
  4. java MD5工具类
  5. 输入法斗图发送微信以及qq实现参考资料
  6. Vert.x 简单介绍
  7. Cocos Creator 3.2 中实现2D地图3D人物45度角RPG游戏完整效果
  8. php+js+背景特效,基于canvas+html5炫酷星空背景动画特效
  9. socket心跳检测和重连小demo
  10. 爱奇艺2015校园招聘产品经理面试题