ZOJ 1450 Minimal Circle 最小圆覆盖
套了个模板直接上,貌似没有随机化序列 QAQ
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
using namespace std; const int INF = 0x3f3f3f3f;
const int MAXN = ;
const double eps = 1e-; struct POINT{
double x;
double y;
POINT() : x(), y() {};
POINT(double _x_, double _y_) : x(_x_), y(_y_) {};
}; struct CIRCLE{
POINT p;
double r;
CIRCLE() {};
CIRCLE(POINT _p_, double _r_) : p(_p_), r(_r_) {};
}; double dist(POINT a,POINT b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} CIRCLE calc(POINT p1,POINT p2,POINT p3){//三点的外接圆圆心的函数:
CIRCLE temp;
double a,b,c,d,e,f;
a = p2.x - p1.x;
b = p2.y - p1.y;
c = (p2.x * p2.x + p2.y * p2.y - p1.x * p1.x - p1.y * p1.y) / ;
d = p3.x - p1.x;
e = p3.y - p1.y;
f = (p3.x * p3.x + p3.y * p3.y - p1.x * p1.x - p1.y * p1.y) / ;
temp.p.y = (c * d - f * a) / (b * d - e * a);
temp.p.x = (c * e - f * b) / (a * e - b * d);
return temp;
}
CIRCLE minC(POINT *p,int n){
CIRCLE O;
int i,j,k;
O.p = p[];
O.r = ;
for(i= ; i < n ; i++){
if(dist(O.p,p[i]) <= O.r + eps) continue;
O.p = p[i];O.r = ;
for(j = ; j < i; j++){
if(dist(O.p,p[j]) <= O.r + eps) continue;
O.p.x = (p[i].x + p[j].x) / ;
O.p.y = (p[i].y + p[j].y) / ;
O.r = dist(O.p,p[j]);
for(k = ; k < j; k++){
if(dist(O.p,p[k]) <= O.r + eps) continue;
O = calc(p[i],p[j],p[k]);
O.r = dist(O.p,p[k]);
}
}
}
return O;
} int main(){
int i, j, n;
POINT p[];
while(EOF != scanf("%d",&n)){
if(n == ) break;
for(i = ; i < n; ++i)
scanf("%lf%lf",&p[i].x,&p[i].y);
CIRCLE c = minC(p, n);
printf("%.2f %.2f %.2f\n",c.p.x,c.p.y,c.r);
}
return ;
}
ZOJ 1450 Minimal Circle 最小圆覆盖的更多相关文章
- zoj 1450 Minimal Circle 最小覆盖圆
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...
- ZOJ1450 Minimal Circle 最小圆覆盖
ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖 考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆. #includ ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- ZOJ1450 Minimal Circle
You are to write a program to find a circle which covers a set of points and has the minimal area. T ...
- [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】
题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...
- [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
- 【做题】POI2011R1 - Plot——最小圆覆盖&倍增
原文链接 https://www.cnblogs.com/cly-none/p/loj2159.html 题意:给出\(n\)个点,你需要按编号将其划分成不超过\(m\)段连续的区间,使得所有每个区间 ...
- 【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)
[BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...
- bzoj 1336 最小圆覆盖
最小圆覆盖 问题:给定平面上的一个点集,求半径最小的一个圆,使得点集中的点都在其内部或上面. 随机增量算法: 定义:点集A的最小圆覆盖是Circle(A) 定理:如果Circle(A)=C1,且a不被 ...
随机推荐
- java 简单的词法分析
package com.seakt.example; import java.io.*; import java.lang.String; public class J_Scanner { publi ...
- xbox360版本之分
2005-11-22 发售精简版 (Core):白色 / 无硬盘 / 主板代号 Xenon(现已停产) 2005-11-22 发售豪华版 (Premium):白色 / 20 GB 硬盘 / 主板代号 ...
- (C#)Windows Shell 编程系列2 - 解释,从“桌面”开始展开
原文 (C#)Windows Shell 编程系列2 - 解释,从“桌面”开始展开 (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一篇:(C#)Windows Shell 编 ...
- iostream.h 和stdio.h区别
stdio.h是C的标准I/O库,是以函数的方式向buffer写入或读取字符.输入输出是这样的printf(...);,scanf(...); iostream是C++的标准I/O库,引入了输入/输出 ...
- .net 中文显示乱码问题(Chinese display with messy code)
Case:同样的代码,本地开发环境(local is Chinese Simplify)可以成功运行,但是放到Windows Server 2008 R2(Local is United State) ...
- shell:监控进程运行状态并自动重启进程
#!/bin/sh MAXRSTCOUNT=; PROCTOGO=/mnt/hgfs/code/test/show #count is the counter of test started time ...
- Objects
Obeject Object Object representation and value representation Subobjects Polyomrphic objecets Alignm ...
- BZOJ 4143 The Lawyer
这道题看起来很吓人,但事实上看懂后会发现,其根本没有任何技术含量,做这道题其实要考虑的就是每天最早结束的一场的结束时间以及最晚开始的一场的开始时间,如果结束时间早于开始时间,那么OK就这 ...
- Android外部存储 - 官方文档解读
预备知识:External Storage Technical Information 摘要: "The WRITE_EXTERNAL_STORAGE permission must onl ...
- 结构体struct和联合体union以及enum枚举体5的区别
下面来自wikipedia: In computer science, a union is a value that may have any of several representations ...