1336: [Balkan2002]Alien最小圆覆盖

Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special Judge
Submit: 1573  Solved: 697
[Submit][Status][Discuss]

Description

给出N个点,让你画一个最小的包含所有点的圆。

Input

先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0)

Output

输出圆的半径,及圆心的坐标

Sample Input

6
8.0 9.0
4.0 7.5
1.0 2.0
5.1 8.7
9.0 2.0
4.5 1.0

Sample Output

5.00
5.00 5.00

HINT

Source

1337: 最小圆覆盖

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 897  Solved: 437
[Submit][Status][Discuss]

Description

给出平面上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

HINT

Source

Solution

最小圆覆盖裸题,随机增量法

这道题有个需要注意的地方,输出的时候不要只输出2位小数,可能会WA,可以考虑直接输出

直接把课件黏上来= =

Code

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<iomanip>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef long double Double; struct Vector
{
double x,y;
Vector(double X=,double Y=) {x=X,y=Y;}
};
typedef Vector Point;
typedef vector<Point> Polygon;
const double eps=1e-;
const double pi=acos(-1.0);
struct Line
{
Point P;
Vector v;
double ang;
Line() {}
Line(Point P,Vector v):P(P),v(v) {ang=atan2(v.y,v.x);}
bool operator<(const Line &L) const {return ang<L.ang;}
};
int dcmp(double x) {if(fabs(x)<eps) return ; else return x<? -:;}
Vector operator + (Vector A,Vector B) {return ((Vector){A.x+B.x,A.y+B.y});}
Vector operator - (Vector A,Vector B) {return ((Vector){A.x-B.x,A.y-B.y});}
Vector operator * (Vector A,double p) {return ((Vector){A.x*p,A.y*p});}
Vector operator / (Vector A,double p) {return ((Vector){A.x/p,A.y/p});}
bool operator < (const Vector& a,const Vector& b) {return a.x<b.x||(a.x==b.x&&a.y<b.y);}
bool operator == (const Vector& a,const Vector& b) {return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;}
double Dot(Vector A,Vector B) {return A.x*B.x+A.y*B.y;}
double Len(Vector A) {return sqrt(Dot(A,A));}
double Cross(Vector A,Vector B) {return A.x*B.y-A.y*B.x;}
Vector Rotate(Vector A,double rad) {return ((Vector){A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad)});}
Point GLI(Point P,Vector v,Point Q,Vector w) {Vector u=P-Q; double t=Cross(w,u)/Cross(v,w); return P+v*t;}
Point GLI(Line a,Line b) {Vector u=a.P-b.P; double t=Cross(b.v,u)/Cross(a.v,b.v);return a.P+a.v*t;}
Point Center_of_gravity(Point A,Point B,Point C)
{
Point P=(A+B)/,Q=(A+C)/;
Vector v=Rotate(B-A,pi/),w=Rotate(C-A,pi/);
if(dcmp(Len(Cross(v,w)))==)//这是三点一线的情况
{
if(dcmp(Len(A-B)+Len(B-C)-Len(A-C))==)
return (A+C)/;
if(dcmp(Len(A-C)+Len(B-C)-Len(A-B))==)
return (A+B)/;
if(dcmp(Len(A-B)+Len(A-C)-Len(B-C))==)
return (B+C)/;
}
return GLI(P,v,Q,w);
}
double Min_Cover_Circle(Point *p,int n,Point &c)
{
random_shuffle(p,p+n);
c=p[];
double r=;
int i,j,k;
for(i=;i<n;i++)
if(dcmp(Len(c-p[i])-r)>)
{
c=p[i],r=;
for(j=;j<i;j++)
if(dcmp(Len(c-p[j])-r)>)
{
c=(p[i]+p[j])/;
r=Len(c-p[i]);
for(k=;k<j;k++)
if(dcmp(Len(c-p[k])-r)>)
{
c=Center_of_gravity(p[i],p[j],p[k]);
r=Len(c-p[i]);
}
}
}
return r;
}
#define MAXN 100010
Point Po[MAXN];
int main()
{
srand();
int n; scanf("%d",&n);
for (int i=; i<=n; i++)
{
double x,y; scanf("%lf%lf",&x,&y);
Po[i-]=Point(x,y);
}
Point c;
printf("%lf\n",Min_Cover_Circle(Po,n,c));
printf("%lf %lf",c.x,c.y);
return ;
}

【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)的更多相关文章

  1. Bzoj 1336&1337 Alien最小圆覆盖

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special Judge Submit: 1473  ...

  2. BZOJ 1337: 最小圆覆盖1336: [Balkan2002]Alien最小圆覆盖(随机增量法)

    今天才知道有一种东西叫随机增量法就来学了= = 挺神奇的= = A.令ci为包括前i个点的最小圆,若第i+1个点无法被ci覆盖,则第i+1个点一定在ci+1上 B.令ci为包括前i个点的最小圆且p在边 ...

  3. [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】

    题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...

  4. 【bzoj1336/1337/2823】[Balkan2002]Alien最小圆覆盖 随机增量法

    题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000. ...

  5. BZOJ.2823.[AHOI2012]信号塔(最小圆覆盖 随机增量法)

    BZOJ 洛谷 一个经典的随机增量法,具体可以看这里,只记一下大体流程. 一个定理:如果一个点\(p\)不在点集\(S\)的最小覆盖圆内,那么它一定在\(S\bigcup p\)的最小覆盖圆上. 所以 ...

  6. 最小圆覆盖(随机增量法&模拟退火法)

    http://acm.hdu.edu.cn/showproblem.php?pid=3007 相关题型连接: http://acm.hdu.edu.cn/showproblem.php?pid=393 ...

  7. BZOJ1336 Balkan2002 Alien最小圆覆盖 【随机增量法】*

    BZOJ1336 Balkan2002 Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000, ...

  8. 【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法

    [BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=10000 ...

  9. 最小圆覆盖(洛谷 P1742 增量法)

    题意:给定N个点,求最小圆覆盖的圆心喝半径.保留10位小数点. N<1e5: 思路:因为精度要求较高,而且N比较大,所以三分套三分的复杂度耶比较高,而且容易出错. 然是写下增量法吧. 伪代码加深 ...

随机推荐

  1. memcached的图形界面监控

    前提是已经安装了php和memcached   图形界面的监控是通过memcache.php来实现的,   1.把该php程序拷贝到apache的web根目录   [root@cacti srv]# ...

  2. mac系统使用内置的 PHP

    从 OS X 10.0.0 版本开始,PHP 作为 Mac 机的标准配置被提供.在默认的 web 服务器中启用 PHP,只需将 Apache 配置文件 httpd.conf 中的几行配置指令最前面的注 ...

  3. Log4net在类库中的用法

    app.config应当放置在解决方案的根目录下.具体流程如下: 第一步:应该下载log4net.dll并引入到你的项目中,下载见附件 第二步:需要配置相关的配置文件App.config或Web.co ...

  4. .htaccess重命名时提示必须键入文件名怎么解决

    在上一篇文章中提到过“目前data.uploads有执行.php权限,非常危险,需要立即取消目录的执行权限!”的时候可以通过创建一个名字为“.htaccess”的文件夹解决.但是在创建的时候却发现对记 ...

  5. Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  6. java:利用xpath删除xml中的空节点

    原始xml内容: <data> <a> </a> <b>b1</b> <awb> <awbpre>123</a ...

  7. 挖掘机力矩限制器/挖掘机称重系统/挖泥机称重/Excavators load protection/Load moment indicator

    挖掘机力矩限制器是臂架型起重机机械的安全保护装置,本产品采用32位高性能微处理器为硬件平台 ,软件算法采用国内最先进的液压取力算法,该算法吸收多年的现场经验,不断改进完善而成.本产品符合<GB1 ...

  8. c8051f320学习,单片机不外乎时钟、IO、串口、USB等外设用法

      时钟 IO(输入.输出,如何配置) IO   数字和模拟资源可以通过25个I/O 引脚(C805 1F3 2 0 ),每个端口引脚都可以被定义为 通用I/O(GPIO)或 0 模拟输入 所有端口I ...

  9. Bootstrap系列 -- 41. 带表单的导航条

    有的导航条中会带有搜索表单,在Bootstrap框架中提供了一个“navbar-form”,使用方法很简单,在navbar容器中放置一个带有navbar-form类名的表单.navbar-left”让 ...

  10. sql server死锁神器

    参考文章: http://blogs.msdn.com/b/sqlserverfaq/archive/2013/04/27/an-in-depth-look-at-sql-server-memory- ...