hdu 4720
最小覆盖圆的模板;
#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的更多相关文章
- HDU 4720 Naive and Silly Muggles 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 题目大意:给你四个点,用前三个点绘制一个最小的圆,而这三个点必须在圆上或者在圆内,判断最一个点如 ...
- HDU 4720 Naive and Silly Muggles 平面几何
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...
- hdu 4720 计算几何简单题
昨天用vim练了一道大水题,今天特地找了道稍难一点的题.不过也不是很难,简单的计算几何而已.练习用vim编码,用gdb调试,结果居然1A了,没调试...囧... 做法很简单,无非就是两种情况:①三个巫 ...
- HDU 4720 Naive and Silly Muggles (外切圆心)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 4720 Naive and Silly Muggles (简单计算几何)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 2013 ACM/ICPC Asia Regional Online —— Warmup2
HDU 4716 A Computer Graphics Problem 水题.略 HDU 4717 The Moving Points 题目:给出n个点的起始位置以及速度矢量,问任意一个时刻使得最远 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- C#读取Exeal文件
今天写一个读取Exeal的时候遇到一个问题就是引用了Mircosotf.Office.Interop.Exeal类库的时候没有办法读取到 纠结了好久百度了一下发现别人是这样写的using Exeal= ...
- Magento入门开发教程
Modules->模块 Controller->控制器 Model->模型 Magento是这个星球上最强大的购物车网店平台.当然,你应该已经对此毫无疑问了.不过,你可能还不知道,M ...
- react 编写组件 五
看以下示例了解如何定义一个组件 // 定义一个组件LikeButton var LikeButton = React.createClass({ // 给state定义初始值 getInitialSt ...
- order by跟group by 跟having(2)
- MVC LINQ中用封装的TSQL通用更新方法
把TSQL拿出来,做了一个封装,适用的所有表,更新有两种,普通更新和记数更新 看代码:这两个方法是写在DAL里的数据操作基类里的,只有它的子类可以用它,所以用protected做为限制 /// < ...
- OC单例模式的实现
SingleClass.m #import <Foundation/Foundation.h> @class SingleClass; static SingleClass *instan ...
- oc文件基本读写及操作
代码: #import <Foundation/Foundation.h> //NSString 写文件 void stringWriteToFile(){ NSString *path ...
- C++ 数组的地址问题学习随笔
二维数组额地址问题学习,本文学习内容参考:http://blog.csdn.net/wwdlk/article/details/6322439 #include<iostream> usi ...
- python 在调用时计算默认值
大家都知道python的默认值是在函数定义时计算出来的, 也就是说默认值只会计算一次, 之后函数调用时, 如果参数没有给出,同一个值会赋值给变量, 这会导致, 如果我们想要一个list默认值, 新手通 ...
- Essential C++ 学习笔记01--基本语法
<Essential C++>1.1-1.4节笔记 1. main 函数 main 函数是代码的入口,若无 main 函数,编译不通过. main 函数通常声明为 int, return ...