最小覆盖圆的模板;

 #include<stdio.h>
#include<string.h>
#include<math.h>
struct Point
{
double x;
double y;
} pt[];
struct Traingle
{
struct Point p[];
};
struct Circle
{
struct Point center;
double r;
} ans;
//计算两点距离
double Dis(struct Point p, struct Point q)
{
double dx=p.x-q.x;
double dy=p.y-q.y;
return sqrt(dx*dx+dy*dy);
}
//计算三角形面积
double Area(struct Traingle ct)
{
return
fabs((ct.p[].x-ct.p[].x)*(ct.p[].y-ct.p[].y)-(ct.p[].x-ct.p[].x)*(ct.p[].y-ct.p[].y))/2.0;
}
//求三角形的外接圆,返回圆心和半径(存在结构体"圆"中)
struct Circle CircumCircle(struct Traingle t)
{
struct Circle tmp;
double a, b, c, c1, c2;
double xA, yA, xB, yB, xC, yC;
a = Dis(t.p[], t.p[]);
b = Dis(t.p[], t.p[]);
c = Dis(t.p[], t.p[]);
//根据S = a * b * c / R / 4;求半径R
tmp.r = (a*b*c)/(Area(t)*4.0);
xA = t.p[].x;
yA = t.p[].y;
xB = t.p[].x;
yB = t.p[].y;
xC = t.p[].x;
yC = t.p[].y;
c1 = (xA*xA+yA*yA - xB*xB-yB*yB) / ;
c2 = (xA*xA+yA*yA - xC*xC-yC*yC) / ;
tmp.center.x = (c1*(yA - yC)-c2*(yA - yB)) / ((xA - xB)*(yA - yC)-(xA - xC)*(yA - yB));
tmp.center.y = (c1*(xA - xC)-c2*(xA - xB)) / ((yA - yB)*(xA - xC)-(yA - yC)*(xA - xB));
return tmp;
}
//确定最小包围圆
struct Circle MinCircle(int num, struct Traingle ct)
{
struct Circle ret;
if (num==) ret.r = 0.0;
else if (num==)
{
ret.center = ct.p[];
ret.r = 0.0;
}
else if (num==)
{
ret.center.x = (ct.p[].x+ct.p[].x)/2.0;
ret.center.y = (ct.p[].y+ct.p[].y)/2.0;
ret.r = Dis(ct.p[], ct.p[])/2.0;
}
else if(num==) ret = CircumCircle(ct);
return ret;
}
//递归实现增量算法
void Dfs(int x, int num, struct Traingle ct)
{
int i, j;
struct Point tmp;
ans = MinCircle(num, ct);
if (num==) return;
for (i=; i<=x; i++)
if (Dis(pt[i], ans.center)>ans.r)
{
ct.p[num]=pt[i];
Dfs(i-, num+, ct);
tmp=pt[i];
for (j=i; j>=; j--)
pt[j]=pt[j-];
pt[]=tmp;
}
}
void Solve(int n)
{
struct Traingle ct;
Dfs(n, , ct);
}
int main (void)
{
int n, i,t;
int ca=;
scanf("%d",&t);
while (t--)
{
for (i=; i<=; i++)
scanf("%lf %lf", &pt[i].x, &pt[i].y);
Solve();
double xx,yy;
scanf("%lf%lf",&xx,&yy);
printf("Case #%d: ",ca++);
if((xx-ans.center.x)*(xx-ans.center.x)+(yy-ans.center.y)*(yy-ans.center.y)<=(ans.r)*(ans.r))
puts("Danger");
else puts("Safe");
}
return ;
}

hdu 4720的更多相关文章

  1. HDU 4720 Naive and Silly Muggles 2013年四川省赛题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 题目大意:给你四个点,用前三个点绘制一个最小的圆,而这三个点必须在圆上或者在圆内,判断最一个点如 ...

  2. HDU 4720 Naive and Silly Muggles 平面几何

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...

  3. hdu 4720 计算几何简单题

    昨天用vim练了一道大水题,今天特地找了道稍难一点的题.不过也不是很难,简单的计算几何而已.练习用vim编码,用gdb调试,结果居然1A了,没调试...囧... 做法很简单,无非就是两种情况:①三个巫 ...

  4. HDU 4720 Naive and Silly Muggles (外切圆心)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  5. HDU 4720 Naive and Silly Muggles (简单计算几何)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  6. 2013 ACM/ICPC Asia Regional Online —— Warmup2

    HDU 4716 A Computer Graphics Problem 水题.略 HDU 4717 The Moving Points 题目:给出n个点的起始位置以及速度矢量,问任意一个时刻使得最远 ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. mongo数据管理java简易版

    mongo是搭建在局域网服务器上的,处理起来比较麻烦,于是自己写了个简单的处理工具. 如果有对java操作mongo不太了解的也可以在这里看下简单的示例. 只有增删改查的功能,而且只支持json格式的 ...

  2. java 四种逻辑运算符

    在java的逻辑运算符中,有这么四类&&(短路与).&(与).||(短路或).|(非短路或) &&和&都表示与,&&表示第一个条件为fa ...

  3. Algorithm

    经过慎重考虑,也经过反复思考.查阅网上相关资料 一位高手对我的建议: 一般要做到50行以内的程序不用调试.100行以内的二分钟内调试成功.acm主要是考算法的 ,主要时间是花在思考算法上,不是花在写程 ...

  4. Excel操作之 导出生成多个sheet页面

    首先需要下载一个NPOI.dll 下载地址:http://download.csdn.net/detail/president810/9503038 using System; using Syste ...

  5. Jquery Table添加行、删除行

    html页面代码 <table id="tblUserInfo"> </table> Js代码 function DealUserInfo(qty){ ) ...

  6. WildFly 9.0.2 + SQLServer + BIRT + JNDI 处理BIRT报表发布时数据源的修改

    一.前提需求说明: 最近在做项目的时候使用jboss WildFly发布BIRT报表,在报表中我是直接添加的JDBC数据源,通过Database URL .用户名和密码连接数据库.后来在部署到正式和测 ...

  7. 使用反射让Spinner选择同一选项时触发onItemSelected事件

    翻看源码,Spinner判断是否触发onItemSelected,是在它的基类AdapterView里面做的: void checkSelectionChanged() { if ((mSelecte ...

  8. 数组做为参数传入Oracle存储过程操作数据库

    p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120%; text-align: justi ...

  9. Java实战之01Struts2-04拦截器、上传下载、OGNL表达式

    十二.Struts2中的拦截器 1.拦截器的重要性 Struts2中的很多功能都是由拦截器完成的.比如:servletConfig,staticParam,params,modelDriven等等. ...

  10. 每天一水SGU347

    今天本来应该要写校题解报告的,但是CF跪了,一题都没JUDGE出来,最后比赛取消了~郁闷啊! 后来闲的无事,就到处看看contest,随便点进去一个,看到一水题,几分钟写完,马上就WA了!~ 题目的信 ...