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实现)
public class Test04 { static int a[] = {9,8,7,6,5,4,3,2,1,11,12,10,19,18,17,16}; public static void ...
- Qt将窗体变为顶层窗体(activateWindow(); 和 raise() )
我们知道,在windows上通过鼠标双击某应用程序图标,该应用程序往往会以顶层窗口的形式呈现在我们面前,但是对于一个已经打开的非顶层窗口,我们怎么将其激活为顶层窗口呢? 要达到激活,这个必须要满足两个 ...
- 01_什么是Elasticsearch
Logstash是一个开源的用于收集,分析和存储日志的工具. Kibana4用来搜索和查看Logstash已索引的日志的web接口.这两个工具都基于 Elasticsearch. Logstash: ...
- ThinkPHP 3.1.2 视图-2
一.模板的使用 (重点) a.规则 模板文件夹下[TPL]/[分组文件夹/][模板主题文件夹/]和模块名同名的文件夹[Index]/和方法名同名的文件[index].html(.tpl) 更换模板文件 ...
- poj 2001 Shortest Prefixes(字典树)
题目链接:http://poj.org/problem?id=2001 思路分析: 在Trie结点中添加数据域childNum,表示以该字符串为前缀的字符数目: 在创建结点时,路径上的所有除叶子节点以 ...
- HDU4099(斐波那契数列与字典树)
题目:Revenge of Fibonacci 题意:给出斐波那契数列的前k位,k不超过40,找出最小的正整数n,满足F(n)的前k位与给定数的前k位相同,斐波那契数列的项数不超过100000. 解析 ...
- 工具篇-TraceView
--- layout: post title: 工具篇-TraceView description: 让我们远离卡顿和黑屏 2015-10-09 category: blog --- ## 让我们远 ...
- iOS离线打包
预备环境 iOS开发环境,Mac OS.XCode 7.2以上版本: 下载HBuilder离线打包iOS版SDK(5+ SDK下载). SDK目录说明 HBuilder-Hello:离线打包演示应用: ...
- 字符串解析成easyui-tree的格式
传入的list: [30 : null : null, 301503 : null : null, 301501 : null : null, 301502 : null : null, 3015 : ...
- js之form表单的获取
js中获取form的方法: 1. 利用表单在文档中的索引或表单的name属性来引用表单 document.forms[i] //得到页面中的第i个表单 document.forms[formName] ...