HDU 4720 Naive and Silly Muggles 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720
题目大意:给你四个点,用前三个点绘制一个最小的圆,而这三个点必须在圆上或者在圆内,判断最一个点如果在圆外则是安全的,否则是危险的。
解题思路:我是先借用了别人的模板求三个点组成的最小的圆的圆心以及半径,就列出了圆的标准方程,将第四个点代入其中,则即可以判断此点是否在圆上还是圆外。
AC代码:
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-;
const int len = ;
struct Point
{
double x,y;
} p[len];
struct Line
{
Point a,b;
};
int dbcmp(double n)
{
return n < -eps ? - : n > eps;
}
double dis(Point a, Point b)
{
return ((a.x-b.x) * ( a.x-b.x) + ( a.y-b.y) * ( a.y-b.y));
} //求两直线的交点
Point intersection(Line u,Line v)
{
Point ret=u.a;
double t=((u.a.x-v.a.x)*(v.b.y-v.a.y)-(u.a.y-v.a.y)*(v.b.x-v.a.x))
/((u.a.x-u.b.x)*(v.b.y-v.a.y)-(u.a.y-u.b.y)*(v.b.x-v.a.x));
ret.x+=(u.b.x-u.a.x)*t;
ret.y+=(u.b.y-u.a.y)*t;
return ret;
}
//三角形外接圆圆心(外心)
Point center(Point a,Point b,Point c)
{
Line u,v;
u.a.x=(a.x+b.x)/;
u.a.y=(a.y+b.y)/;
u.b.x=u.a.x+(u.a.y-a.y);
u.b.y=u.a.y-(u.a.x-a.x);
v.a.x=(a.x+c.x)/;
v.a.y=(a.y+c.y)/;
v.b.x=v.a.x+(v.a.y-a.y);
v.b.y=v.a.y-(v.a.x-a.x);
return intersection(u,v);
} void min_cir(Point * p, int n, Point & cir, double &r)
{
random_shuffle(p, p + n);
cir = p[];
r = ;
for(int i = ; i < n; ++i)
{
if(dbcmp(dis(p[i],cir) -r) <= )continue;
cir = p[i];
r = ;
for(int j =; j < i ; ++j)
{
if(dbcmp(dis(p[j], cir) -r) <= )continue;
cir.x = (p[i].x + p[j].x) /;
cir.y = (p[i].y + p[j].y) /;
r = dis( cir, p[j]);
for(int k =; k < j; ++k)
{
if(dbcmp( dis(p[k], cir) -r) <= ) continue;
cir = center(p[i], p[j], p[k]);
r = dis( cir, p[k]);
} }
}
}
int main()
{
int t;
scanf("%d",&t);
for(int ca=; ca<=t; ca++)
{
for (int i = ; i < ; ++i)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
}
Point cir;
double r,dd,ee;
scanf("%lf%lf",&dd,&ee);
min_cir(p, , cir, r);
double aa=cir.x,bb=cir.y,cc=r;
double z=(dd-aa)*(dd-aa)+(ee-bb)*(ee-bb); if(z-cc>eps) printf("Case #%d: Safe\n",ca);
else printf("Case #%d: Danger\n",ca);
//printf("%lf %lf %lf %lf\n", aa, bb, cc,z);
}
return ;
}
HDU 4720 Naive and Silly Muggles 2013年四川省赛题的更多相关文章
- 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/ ...
- HDU 4720 Naive and Silly Muggles 平面几何
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...
- HDU 4716 A Computer Graphics Problem 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4716 题目大意不用解释了吧,看案例就能明白 #include<cstdio> #inclu ...
- 计算几何 HDOJ 4720 Naive and Silly Muggles
题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/a ...
- HDU 4727 The Number Off of FFF 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4727 题目大意:队列里所有人进行报数,要找出报错的那个人 思路:,只要找出序列中与钱一个人的数字差不是 ...
- HDU 4722 Good Numbers 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 题目大意:给定一个区间,求区间中有多少个满足每位上的数的和是10的倍数. 解题思路:先打表暴力求 ...
- Naive and Silly Muggles
Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...
- Naive and Silly Muggles (计算几何)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- (转)ASP.NET QueryString乱码解决问题
正常的情况下,现在asp.net的网站很多都直接使用UTF8来进行页面编码的,这与Javascript.缺省网站的编码是相同的,但是也有相当一部分采用GB2312. 对于GB2312的网站如果直接用j ...
- 转--浅谈ETL
ETL是将业务系统的数据经过抽取.清洗转换之后加载到数据仓库的过程,目的是将企业中的分散.零乱.标准不统一的数据整合到一起,为企业的决策提供分析依据. ETL是BI项目重要的一个环节. 通常情况下,在 ...
- ASP.NET Web API教程(六) 安全与身份认证
在实际的项目应用中,很多时候都需要保证数据的安全和可靠,如何来保证数据的安全呢?做法有很多,最常见的就是进行身份验证.验证通过,根据验证过的身份给与对应访问权限.同在Web Api中如何实现身份认证呢 ...
- ios专题 - 斯坦福大学iOS开发公开课总结
转自:http://blog.devtang.com/blog/2012/02/05/mvc-in-ios-develop/ 前言 iphone开发相关的教程中最有名的,当数斯坦福大学发布的”ipho ...
- JavaScript Invalid Date Verify
if ( Object.prototype.toString.call(d) === "[object Date]" ) { // it is a date if ( isNaN( ...
- Introduction to object
1 Declarations VS definitions (Page 81) declarations: This function or variable exists somew ...
- MFC中cannot find the definition (implementation) of this function 解决方法
问题:使用vc6 在点击左侧class view中的一个方法实现时出现下面错误: cannot find the definition (implementation) of this func ...
- 开发错误日志之No matching bean of type [xxx] found for dependency
No matching bean of type [org.springframework.data.mongodb.core.MongoTemplate] found for dependency ...
- HTML5储存
1.sessionStorage 特点:关闭浏览器(或标签页)后数据就不存在了.但刷新页面或使用“前进”.“后退按钮”后sessionStorage仍然存在: sessionStorage每个窗口的值 ...
- runas /user:administrator cmd 以管理员身份运行CMD
runas /user:administrator cmd 以管理员身份运行CMD 1.windows+r打开 2.然后根据提示输入密码