ZOJ1450 Minimal Circle
You are to write a program to find a circle which covers a set of points and has the minimal area. There will be no more than 100 points in one problem.
Input
The input contains several problems. The first line of each problem is a line containing only one integer N which indicates the number of points to be covered. The next N lines contain N points. Each point is represented by x and y coordinates separated by a space. After the last problem, there will be a line contains only a zero.
Output
For each input problem, you should give a one-line answer which contains three numbers separated by spaces. The first two numbers indicate the x and y coordinates of the result circle, and the third number is the radius of the circle. (use escape sequence %.2f)
Sample Input
2
0.0 0.0
3 0
5
0 0
0 1
1 0
1 1
2 2
0
Sample Output
1.50 0.00 1.50
1.00 1.00 1.41
数学问题 几何
最小圆覆盖,随机增量法
其实就是枚举两个点作为圆直径上的两点,发现有点在当前圆外时,就调整直径……
随机增量法求最小圆覆盖。
三重循环。
令ci为前i个点的覆盖圆,新加入一个点i+1时,若其在圆内,跳过,若其在圆外,修改圆心使i+1在圆c(i+1)上。
检查之前的点,令ci为前i个点的覆盖圆,且点j在圆周上,若第i+1个点无法被圆覆盖,修改圆心使点i+1和点j都在圆周上。
检查之前的点,令ci为前i个点的覆盖圆,且点j和点k在圆周上,若第i+1个点无法被圆覆盖,修改圆心使点i+1和点j、点k都在圆周上
这算法倒是还能理解,但是求外心的几何算法表示看不懂。这个技能还是等高二再解锁吧。
——高一时候的博主
↑什么解锁技能啊……现在一回顾,就是设外心坐标,根据外心到三个顶点的距离相等来暴力列方程,解出来个表达式就行……
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-;
const int mxn=;
struct Point{
double x,y;
Point operator + (Point rhs){return (Point){x+rhs.x,y+rhs.y};}
Point operator - (Point rhs){return (Point){x-rhs.x,y-rhs.y};}
double cross(Point rhs){return x*rhs.y-y*rhs.x;}
friend double dist(Point a,Point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
}p[mxn],O;
int n;
double r;
void clc(Point p1,Point p2,Point p3){//计算三角形外心
double a=*(p2.x-p1.x);
double b=*(p2.y-p1.y);
double c=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
double d=*(p3.x-p1.x);
double e=*(p3.y-p1.y);
double f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
O.y=(d*c-a*f)/(b*d-e*a);
O.x=(b*f-e*c)/(b*d-e*a);
r=dist(O,p1);
return;
}
int main(){
int i,j;
while(scanf("%d",&n) && n){
for(i=;i<=n;i++){scanf("%lf%lf",&p[i].x,&p[i].y);}
O=p[];r=;
for(int i=;i<=n;i++)
if(dist(O,p[i])>r+eps){
O=p[i];r=;
for(j=;j<i;j++){
if(dist(O,p[j])>r+eps){
O.x=(p[i].x+p[j].x)/;
O.y=(p[i].y+p[j].y)/;
r=dist(O,p[j]);
for(int k=;k<j;k++){
if(dist(O,p[k])>r+eps)
clc(p[i],p[j],p[k]);
}
}
}
}
printf("%.2f %.2f %.2f\n",O.x,O.y,r);
}
return ;
}
ZOJ1450 Minimal Circle的更多相关文章
- ZOJ1450 Minimal Circle 最小圆覆盖
ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖 考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆. #includ ...
- zoj 1450 Minimal Circle 最小覆盖圆
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...
- ZOJ 1450 Minimal Circle 最小圆覆盖
套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- ZOJ1450 BZOJ1136 BZOJ1137 HDU3932[最小圆覆盖]
Minimal Circle Time Limit: 5 Seconds Memory Limit: 32768 KB You are to write a program to find ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- Bootstrap Thumbnail
Square Thumbnail with Image <!-- Square Thumbnail with Image --> <com.beardedhen.androidboo ...
- (译)Minimal Shader(最小的着色器)
(原文:https://en.wikibooks.org/wiki/Cg_Programming/Unity/Minimal_Shader) This tutorial covers the basi ...
- Centos 7 minimal install 无网络无ifconfig的解决
Centos7这个比较不厚道, minimal install下居然不带net-tools 先要连上网络 修改/etc/sysconfig/network-scripts/ifcfg-ens12312 ...
随机推荐
- torndb在python3中运用
#连接数据库:db = torndb.Connect() #查询一条的数据get() #查询多行的数据query() #创建数据表,数据库execute() #插入一条数据:sql = "i ...
- VSCode 前端必备插件
VSCode 前端必备插件 Debugger for Chrome 让 vscode 映射 chrome 的 debug功能,静态页面都可以用 vscode 来打断点调试 { "versio ...
- GBDT && XGBOOST
GBDT && XGBOOST Outline Introduction GBDT Model XGBOOST Model ...
- [leetcode-652-Find Duplicate Subtrees]
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...
- WebStorm强大的调试JavaScript功能(转载)
一.JavaScript的调试 目前火狐和Chrome都具备调试JavaScript的功能,而且还是相当的强大.如果纯粹是用浏览器来进行js调试的话,我比较喜欢用火狐.火狐可以安装各种插件,真的是非常 ...
- Zebra - zebra command to get printer error and warning status
1 Flag2 Nibble 16-93 Nibble 8-44 Nibble 35 Nibble 26 Nibble 1
- 一个python游戏源码
#finalPyPong.py import pygame,sys class MyBallClass(pygame.sprite.Sprite): def __init__(self,image_f ...
- C++编码规范101
组织和策略问题 第0条 不要拘泥于小节(又名:了解哪些东西不应该标准化) 第1条 在高警告级别干净利落地进行编译 第2条 使用自动构建系统 第3条 使用版本控制系统 第4条 在代码审查上投入 设计风格 ...
- 基于log4j的消息流的实现之二消息传递
在“基于log4j的消息流的实现之一消息获取”中获取日志消息的部分,修改如下: import org.apache.commons.collections.map.HashedMap; import ...
- rpc通信模型
1.client_stub是为了屏蔽客户端调用远程主机的对象,而在本地的一个对象存根,存根负责接受本地方法调用,并将其序列化,然后通过网络发送给服务端.