【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
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
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
HINT
Source
1337: 最小圆覆盖
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 897 Solved: 437
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 0
0 1
0 -1
-1 0
Sample Output
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最小圆覆盖 最小圆覆盖(随机增量法)的更多相关文章
- Bzoj 1336&1337 Alien最小圆覆盖
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge Submit: 1473 ...
- BZOJ 1337: 最小圆覆盖1336: [Balkan2002]Alien最小圆覆盖(随机增量法)
今天才知道有一种东西叫随机增量法就来学了= = 挺神奇的= = A.令ci为包括前i个点的最小圆,若第i+1个点无法被ci覆盖,则第i+1个点一定在ci+1上 B.令ci为包括前i个点的最小圆且p在边 ...
- [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
- 【bzoj1336/1337/2823】[Balkan2002]Alien最小圆覆盖 随机增量法
题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000. ...
- BZOJ.2823.[AHOI2012]信号塔(最小圆覆盖 随机增量法)
BZOJ 洛谷 一个经典的随机增量法,具体可以看这里,只记一下大体流程. 一个定理:如果一个点\(p\)不在点集\(S\)的最小覆盖圆内,那么它一定在\(S\bigcup p\)的最小覆盖圆上. 所以 ...
- 最小圆覆盖(随机增量法&模拟退火法)
http://acm.hdu.edu.cn/showproblem.php?pid=3007 相关题型连接: http://acm.hdu.edu.cn/showproblem.php?pid=393 ...
- BZOJ1336 Balkan2002 Alien最小圆覆盖 【随机增量法】*
BZOJ1336 Balkan2002 Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000, ...
- 【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法
[BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=10000 ...
- 最小圆覆盖(洛谷 P1742 增量法)
题意:给定N个点,求最小圆覆盖的圆心喝半径.保留10位小数点. N<1e5: 思路:因为精度要求较高,而且N比较大,所以三分套三分的复杂度耶比较高,而且容易出错. 然是写下增量法吧. 伪代码加深 ...
随机推荐
- PAT 1009. 说反话 (20) JAVA
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串.字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区 ...
- [LINK]OpenResty
http://openresty.org/ http://www.tuicool.com/articles/M3yI3y http://www.oschina.net/question/28_6046 ...
- keytool命令记录
1.生成服务器端私钥kserver.keystore文件 2.根据私钥,导出服务器端安全证书 3.将服务器端证书,导入到客户端的Trust KeyStore中 4.生成客户端私钥kclient.key ...
- tomcat配置文件详解
Tomcat系列之服务器的安装与配置以及各组件详解 tomcat 配置文件详解
- SQL server 数据库备份还原Sql
/************ 一.数据库备份 ************/ --完整备份默认追加到现有的文件 backup database DBXS To disk='d:\backup\DBXS_fu ...
- 2016古装动作喜剧《笨贼别跑》HD720P.国语中字
导演: 雷金克编剧: 郭卫鹏 / 李诗怡 / 马强主演: 彭波 / 李添诺 / 董向荣 / 韩丰 / 董怡君类型: 喜剧 / 动作 / 古装制片国家/地区: 中国大陆语言: 汉语普通话上映日期: 20 ...
- mongodb .net core 调用
MongoClient _client; IMongoDatabase _db; MongoCredential credential = MongoCredential.CreateMongoCRC ...
- 产品列表页分类筛选、排序的算法实现(PHP)
一.简单的单条件查询 工作都是从简单的开始,先从最简单的单表查询开始,这个一般用在首页以及一些比较独立的页面,只需要查找几个符合条件的产品展示出来即可,可以使用分页或者不使用分页.下面这个是产品控制器 ...
- 后缀树(BZOJ3238TLE)
#include<cstdio> #include<cstring> #define LL long long ],stt[]; LL ans; ,sidcnt,lastcre ...
- STL中algorithm里的查找
首先,选择查找算法时,区间是否排序是一个至关重要的因素.可以按是否需要排序区间分为两组: A. count,find B. binary_search,lower_bound,upper_bound, ...