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. AFNetworking 与 UIKit+AFNetworking 详解

    资料来源 : http://github.ibireme.com/github/list/ios GitHub : 链接地址 简介 : A delightful iOS and OS X networ ...

  2. java多线程系类:基础篇:04synchronized关键字

    概要 本章,会对synchronized关键字进行介绍.涉及到的内容包括:1. synchronized原理2. synchronized基本规则3. synchronized方法 和 synchro ...

  3. BZOJ 4717 改装

    Description [题目背景] 小Q最近喜欢上了一款游戏,名为<舰队connection>,在游戏中,小Q指挥强大的舰队南征北战,从而成为了一名dalao.在游戏中,不仅船只能力很重 ...

  4. jboss eap 6.2+ 版本中 加密datasource密码等敏感信息

    默认情况下,在jboss eap 6.2+ 管理控制台创建datasource后,会在standalone.xml(独立模式)或host.xml(域模式)中以明文保存相关敏感信息. 这会给服务器留下安 ...

  5. PAT 1067. Sort with Swap(0,*)

    1067. Sort with Swap(0,*) (25)   Given any permutation of the numbers {0, 1, 2,..., N-1}, it is easy ...

  6. 【REST WCF】30分钟理论到实践

    先来点理论知识,来自 http://www.cnblogs.com/simonchen/articles/2220838.html 一.什么是Rest REST软件架构是由Roy Thomas Fie ...

  7. ASP.NET 系列:单元测试之SmtpClient

    使用SmtpClient发送Email时,我们可以创建ISmtpClient接口和SmtpClientWrapper适配类,在单元测试中对ISmtpClient进行Mock或自定义FackeSmtpC ...

  8. 理解Android安全机制

    本文从Android系统架构着手,分析Android的安全机制以SE Android,最后给出一些Android安全现状和常见的安全解决方案. 1.Android系统架构 Android采用分层的系统 ...

  9. DSOFramer 之一:在 64 位系统注册 DSOFramer

    DSOFramer是微软提供的一款用于在线编辑.调用Word.Excel等Office程序的ActiveX组件.很多第三方的Office组件都是基于DSOFramer组件开发的.今天我们不讲如何使用D ...

  10. Cadence Allegro元件封装制作流程

    (本文为转载,原文出处不详) 引言 一个元件封装的制作过程如下图所示.简单来说,首先用户需要制作自己的焊盘库Pads,包括普通焊盘形状Shape Symbol和花焊盘形状Flash Symbol:然后 ...