HDU 3007
基本小圆覆盖模板题
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int X,Y; int n;
const double eps=0.00000001;
struct point{
double x,y;
}p[550]; struct Circle{
point cent;
double r;
}cir; double dist(point x, point y){
double a=x.x-y.x;
double b=x.y-y.y;
return sqrt(a*a+b*b);
} double triangleArea(point t1, point t2, point t3){
point p1,p2;
p1.x=t2.x-t1.x; p1.y=t2.y-t1.y;
p2.x=t3.x-t1.x; p2.y=t3.y-t1.y;
return fabs(p1.x*p2.y-p1.y*p2.x)/2;
} Circle triangleCircle(point t1, point t2, point t3){
Circle tmp;
double a=dist(t1,t2);
double b=dist(t2,t3);
double c=dist(t3,t1);
tmp.r=a*b*c/triangleArea(t1,t2,t3)/4;
double xa,ya,xb,yb,xc,yc;
double c1,c2;
xa=t1.x; ya= t1.y;
xb=t2.x; yb= t2.y;
xc=t3.x; yc= t3.y;
c1=(xa*xa+ya*ya-xb*xb-yb*yb)/2;
c2=(xa*xa+ya*ya-xc*xc-yc*yc)/2;
tmp.cent.x=(c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb));
tmp.cent.y=(c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb));
return tmp;
} void slove(){
random_shuffle(p,p+n);
cir.cent=p[0];
cir.r=0;
for(int i=1;i<n;i++){
if(dist(cir.cent,p[i])>cir.r){
cir.cent=p[i]; cir.r=0;
for(int j=0;j<i;j++){
if(dist(cir.cent,p[j])>cir.r){
cir.cent.x=(p[i].x+p[j].x)/2;
cir.cent.y=(p[i].y+p[j].y)/2;
cir.r=dist(p[i],p[j])/2;
for(int k=0;k<j;k++){
if(dist(cir.cent,p[k])>cir.r){
cir=triangleCircle(p[i],p[j],p[k]);
}
}
}
}
}
}
} int main (){
while(scanf("%d",&n),n){
for(int i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
slove();
printf("%0.2lf %0.2lf ",cir.cent.x,cir.cent.y);
printf("%0.2lf\n",cir.r);
}
return 0;
}
HDU 3007的更多相关文章
- hdu 3007 Buried memory 最远点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- HDU 3007 模拟退火算法
Buried memory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)
Problem Description Each person had do something foolish along with his or her growth.But,when he or ...
- hdu 3007【最小圆覆盖-随机增量法模板】
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> usin ...
- HDU 3007 最小圆覆盖 计算几何
思路: 随机增量法 (好吧这数据范围并不用) //By SiriusRen #include <cmath> #include <cstdio> #include <al ...
- HDU - 3007 Buried memory
传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
随机推荐
- 机器学习——Day 2 简单线性回归
写在开头 由于某些原因开始了机器学习,为了更好的理解和深入的思考(记录)所以开始写博客. 学习教程来源于github的Avik-Jain的100-Days-Of-MLCode 英文版:https:// ...
- 2015 多校赛 第五场 1010 (hdu 5352)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...
- WPF播放器
最近由于工作需要,需要做一个播放软件,在网上参考了很多例子,园子里有很多代码.其中最多的就是wpf自带的MediaElement控件,或者VLC视频播放器. 先附我自己查询资料的链接: MediaEm ...
- 【Oracle】服务器端监听配置
一.静态监听 创建端口为1521的监听,静态注册,本机ip:192.168.10.2 [oracle@localhost ~]$ vi /u01/app/oracle/product/11.2.0/d ...
- Java_Web之JSTL和EL
今天学了JSTL和EL,替换了以前for循环,感觉代码越来越少了,十分方便.JSTL和EL密不可分. 一.什么是EL表达式? 什么是EL EL即Expression Language(表达式语言) E ...
- mvc自定义控件
//自定义一个DatePicker.cshtml文件@helper Init() { <link href="~/Content/mobiscroll.custom-2.5.0.min ...
- HDU_1850_nim游戏
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- excel 处理方法
//.方法一:采用OleDB读取EXCEL文件: //打开excel 返回指定表中的所有数据 public DataSet ExcelToDS(string Path) { string strCon ...
- 用了那么多项目管理工具,还是CORNERSTONE这款最好用
在与软件开发有关的项目,往往会出现很难管理情况.许多事情都需提前计划.控制与管理,所以许多项目经理很容易迷失在计划的过程中.幸运的是,市场上提供了各种各样的项目管理工具.但不幸的是,工具实在是太多了. ...
- Django逻辑关系
title: Django学习笔记 subtitle: 1. Django逻辑关系 date: 2018-12-14 10:17:28 --- Django逻辑关系 本文档主要基于Django2.2官 ...