BZOJ1337: 最小圆覆盖
题目:求n个点的最小圆覆盖。
题解:最小圆覆盖,上模板。复杂度证明可以戳:这里
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1000000+5
#define maxm 200000+5
#define eps 1e-6
#define ll long long
#define ull unsigned long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
#define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
#define mod 1000000007
#define lch k<<1,l,mid
#define rch k<<1|1,mid+1,r
#define sqr(x) (x)*(x)
#define db double
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
struct point
{
db x,y;
point operator +(point b){return (point){x+b.x,y+b.y};}
point operator /(db b){return (point){x/b,y/b};}
}a[maxn];
int n;
db ans;
inline db dist(point a,point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
inline point calc(db a,db b,db c,db d,db e,db f)
{
return (point){(c*e-f*b)/(a*e-d*b),(a*f-c*d)/(a*e-d*b)};
}
inline point get(point a,point b,point c)
{
return calc(b.x-a.x,b.y-a.y,(sqr(b.x)+sqr(b.y)-sqr(a.x)-sqr(a.y))/2.0,
c.x-b.x,c.y-b.y,(sqr(c.x)+sqr(c.y)-sqr(b.x)-sqr(b.y))/2.0);
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)scanf("%lf%lf",&a[i].x,&a[i].y);
for1(i,n)swap(a[rand()%n+],a[rand()%n+]);
ans=;
for1(i,n)if(dist(a[i],a[])>ans+eps)
{
a[]=a[i];ans=;
for1(j,i-)if(dist(a[j],a[])>ans+eps)
{
a[]=(a[i]+a[j])/;ans=dist(a[],a[i]);
for1(k,j-)if(dist(a[k],a[])>ans+eps)
{
a[]=get(a[i],a[j],a[k]);ans=dist(a[],a[i]);
}
}
}
printf("%.2f %.2f %.2f\n",a[].x,a[].y,ans);
return ;
}
我不会说告诉你这题是三倍经验的
BZOJ1337: 最小圆覆盖的更多相关文章
- [BZOJ2823][BZOJ1336][BZOJ1337]最小圆覆盖(随机增量法)
算法介绍网上有很多,不解释了. 给出三点坐标求圆心方法:https://blog.csdn.net/liyuanbhu/article/details/52891868 记得先random_shuff ...
- luoguP1742 最小圆覆盖
最小圆覆盖 首先 没错,我是个蒟蒻.luogu 流程 圆 C; for(i=1 to n) { if(P[i] 不在 C 内) { C = {P[i], 0}; for(j=1 to i-1) { i ...
- 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1573 ...
- Bzoj 1336&1337 Alien最小圆覆盖
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge Submit: 1473 ...
- hdu3007Buried memory(最小圆覆盖)
链接 普通的暴力复杂度达到O(n^4),对于这题肯定是不行的. 解法:随机增量算法 参考http://www.2cto.com/kf/201208/149602.html algorithm:A.令C ...
- [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】
题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...
- [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- bzoj1336: [Balkan2002]Alien最小圆覆盖
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...
随机推荐
- Python - 计算个人所得税
最近在学python,写了个计算个人所得税计算的脚本,分享. 以下为python3适用版本 #!/usr/bin/python # -*- coding: UTF-8 -*- # 该python脚本用 ...
- linux学习笔记-11.正则表达式
1.cut截取以:分割保留第七段 grep hadoop /etc/passwd | cut -d: -f7 2.排序 du | sort -n 3.查询不包含hadoop的 grep -v hado ...
- ehcache 在web项目中使用
无论是servlet web项目还是spring web项目,使用ehcache添加3个jre包以及配置 ehcache.xml即可.
- C/C++的64为长整型数的表示
在C/C++中,64为整型一直是一种没有确定规范的数据类型.现今主流的编译器中,对64为整型的支持也是标准不一,形态各异.一般来说,64位整型的定义方式有long long和__int64两种(VC还 ...
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
- 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem L. Stock Trading Robot 水题
Problem L. Stock Trading Robot 题目连接: http://www.codeforces.com/gym/100253 Description CyberTrader is ...
- 原生javascript封装的函数
1.javascript 加载的函数 window.onload = function(){} 2.封装的id函数 function $(id) { return document.getElemen ...
- js 弹窗广告24小时显示一次
弹窗24小时显示一次 https://www.w3cschool.cn/javascript/js-cookies.html 我们需要借助cookie来实现这个功能 function setcooki ...
- HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- stm32f103串口实现映射功能
在实际开发中,常常遇到串口的默认输出IO口被其它模块占用了,所以我们要用到串口IO口映射功能.是指将原来实现功能的IO口映射到其它指定IO口,其它不变.详细操作例如以下: 先贴出默认下的串口初始化设置 ...