最小覆盖圆的模板;

 #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. 考试必备神器-真题园手机客户端Android版1.1正式上线啦,欢迎大家下载使用!

    真题园-考试必备神器,爱学习,找真题! 真题园-考试必备神器,爱学习,找真题!1.真题园android客户端1.1版全新发布上线.2.最新教育资讯实时更新,了解行业动态新闻.3.最新最全的真题大全,最 ...

  2. Java RMI详解

    RMI:远程方法调用(Remote Method Invocation).能够让在某个java虚拟机上的对象像调用本地对象一样调用另一个java 虚拟机中的对象上的方法. RMI远程调用步骤: 1,客 ...

  3. Java并发——ReentrantLock类源码阅读

    ReentrantLock内部由Sync类实例实现. Sync类定义于ReentrantLock内部. Sync继承于AbstractQueuedSynchronizer. AbstractQueue ...

  4. cognos 10.2.2 report studio数字---字符型查询注意事项

    做了一个简单的报表,就是按照员工编号查询员工,其中员工编号是全数字,我们保存在数据库中的是字符型varchar2(10),所以在report studio中做查询就一直报告服务器错误. 其中使用cas ...

  5. 近期专案PM相关收获

    1, 厚黑学讲的有道理, 坏人? 为什么占便宜., 好人为什么当不了坏人是有一定道理的.     -- 作为PM,能力大小居然都能胜任,从这一点上对组员不负责,如下种种都算有则改之无则加勉.      ...

  6. Codevs 2843 拯救炜哥

    2843 拯救炜哥 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 有一天,炜哥和欧能干一起去大魔王家里做(dao)客(luan), ...

  7. 2016.08.07计算几何总结测试day2

    T1 bzoj: [Usaco2010 OPen]Triangle Counting 数三角形 看到这个题n那么大, 于是想到极角排序搞一搞,然而排完序后立马懵逼,完全不知道接下来应该怎么写.... ...

  8. DataReader 和 DataSet 的区别

    摘自:http://www.cnblogs.com/zhjjNo1/archive/2009/08/26/1554420.html 第一种解释 DataReader和DataSet最大的区别在于,Da ...

  9. LAMP 环境 快速安装

    (一)安装Apache 1.下载安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 yum install zlib-devel -y wget http://m ...

  10. 挂载磁盘的问题(/dev/sdb1 is apparently in use by the system; will not make a 文件系统 here!)

    用fdisk给新磁盘分区后.然后要创建文件系统 [root@cuizhipeng ~]# mkfs.ext4 /dev/sdb1mke2fs 1.41.12 (17-May-2010)/dev/sdb ...