题意:

      给你四个点,问你第四个点是否在前三个点围成的三角形的外接圆上.

思路:

      水题,就是练练用魔板罢了,当该三角形是锐角三角形的时候,圆心是任意两条边中垂线的交点,半径是圆心到任意一点的距离,否则圆心就是最长的那条边的中点位置,半径就是最长的那条边的一半..


#include <cstdio>
#include <cmath>
#include <algorithm>
#define maxn 60
#define eps 1e-7
using namespace std;
int
dcmp(double x) //控制精度
{
if(
fabs(x)<eps) return 0;
else return
x<0?-1:1;
}
double
toRad(double deg) //角度转弧度
{
return
deg/180.0*acos(-1.0);
}
struct
Point
{
double
x,y;
Point(){}
Point(double x,double y):x(x),y(y) {}
void
input()
{

scanf("%lf %lf",&x,&y);
}
};
typedef
Point Vector;
Vector operator+( Vector A, Vector B ) //向量加
{
return
Vector( A.x + B.x, A.y + B.y );
}

Vector operator-(Vector A,Vector B) //向量减
{
return
Vector( A.x - B.x, A.y - B.y );
}

Vector operator*( Vector A, double p ) //向量数乘
{
return
Vector( A.x * p, A.y * p );
}

Vector operator/( Vector A, double p ) //向量数除
{
return
Vector( A.x / p, A.y / p );
}
bool operator<(const
Point& A, const Point& B ) //两点比较
{
return
dcmp( A.x - B.x ) < 0 || ( dcmp( A.x - B.x ) == 0 && dcmp( A.y - B.y ) < 0 );
}
bool operator==( const
Point& a, const Point& b ) //两点相等
{
return
dcmp( a.x - b.x ) == 0 && dcmp( a.y - b.y ) == 0;
}
struct
Line
{

Point s,e;
Vector v;
Line() {}
Line(Point s,Point v,int type)://法向量式
s(s),v(v){}
Line(Point s,Point e):s(s),e(e)//两点式
{v=e-s;} };
double
Dot(Vector A,Vector B)//向量点乘
{
return
A.x*B.x+A.y*B.y;
}
double
Length(Vector A)//向量模
{
return
sqrt(Dot(A,A));
}
double
Angle(Vector A,Vector B)//向量夹角
{
return
acos(Dot(A,B)/Length(A)/Length(B));
}
double
Cross(Vector A,Vector B)//向量叉积
{
return
A.x*B.y-A.y*B.x;
}
double
Area2(Point A,Point B,Point C )//向量有向面积
{
return
Cross(B-A,C-A);
}
double
Dist(Point A,Point B)
{
return
Length(A-B);
}

Vector Rotate(Vector A, double rad)//向量逆时针旋转
{
return
Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}

Vector Normal(Vector A)//向量单位法向量
{
double
L=Length(A);
return
Vector(-A.y/L,A.x/L);
}

Point GetLineIntersection(Line l1,Line l2)//两直线交点
{
Point P=l1.s;
Vector v=l1.v;
Point Q=l2.s;
Vector w=l2.v;
Vector u=P-Q;
double
t=Cross(w,u)/Cross(v,w);
return
P+v*t;
}
double
DistanceToLine(Point P,Line L)//点到直线的距离
{
Point A,B;
A=L.s,B=L.e;
Vector v1=B-A,v2=P-A;
return
fabs(Cross(v1,v2))/Length(v1);
}
double
DistanceToSegment(Point P, Line L)//点到线段的距离
{
Point A,B;
A=L.s,B=L.e;
if(
A==B) return Length(P-A);
Vector v1=B-A,v2=P-A,v3=P-B;
if (
dcmp(Dot(v1,v2))<0) return Length(v2);
else if (
dcmp(Dot(v1,v3))>0) return Length(v3);
else return
fabs(Cross(v1,v2)) / Length(v1);
}

Point GetLineProjection(Point P,Line L)// 点在直线上的投影
{
Point A,B;
A=L.s,B=L.e;
Vector v=B-A;
return
A+v*(Dot(v,P-A)/Dot(v,v));
}
bool
OnSegment(Point p,Line l)//点在线段上包括端点
{
Point a1=l.s;
Point a2=l.e;
return
dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dist(p,a1)+Dist(p,a2)-Dist(a1,a2))==0;
}
bool
Paralled(Line l1,Line l2)//直线平行
{
return
dcmp(Cross(l1.e-l1.s,l2.e-l2.s))==0;
}
bool
SegmentProperIntersection(Line l1,Line l2)//线段相交
{
if(
Paralled(l1,l2))
{
return
false;
}

Point t=GetLineIntersection(l1,l2);
if(
OnSegment(t,l1))
{
return
true;
}
return
false;
}
int
ConvexHull(Point *p,int n,Point *ch) //求凸包
{
sort(p,p+n);
int
m=0;
for ( int
i = 0; i < n; ++i )
{
while (
m > 1 && Cross( ch[m - 1] - ch[m - 2], p[i] - ch[m - 2] ) <= 0 ) --m;
ch[m++] = p[i];
}
int
k = m;
for ( int
i = n - 2; i >= 0; --i )
{
while (
m > k && Cross( ch[m - 1] - ch[m - 2], p[i] - ch[m - 2] ) <= 0 ) --m;
ch[m++] = p[i];
}
if (
n > 1 ) --m;
return
m;
}
double
PolygonArea(Point *p,int n) //多边形有向面积
{
double
area=0;
for (int
i=1;i<n-1;++i)
area+=Cross(p[i]-p[0],p[i+1]-p[0]);
return
area/2.0;
} double
dis(Point A ,Point B)
{
double
tmp = (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
return
sqrt(tmp);
} typedef struct
{
double
dis;
Point A ,B;
}
EDGE; EDGE edge[5]; bool campp(EDGE a ,EDGE b)
{
return
a.dis < b.dis;
} int main ()
{
int
t ,i ,cas = 1;
Point p1 ,p2 ,p3 ,p;
Point O;
double
R;
scanf("%d" ,&t);
while(
t--)
{

scanf("%lf %lf" ,&p1.x ,&p1.y);
scanf("%lf %lf" ,&p2.x ,&p2.y);
scanf("%lf %lf" ,&p3.x ,&p3.y);
scanf("%lf %lf" ,&p.x ,&p.y);
edge[1].A = p1 ,edge[1].B = p2;
edge[2].A = p1 ,edge[2].B = p3;
edge[3].A = p2 ,edge[3].B = p3;
edge[1].dis = dis(p1 ,p2);
edge[2].dis = dis(p1 ,p3);
edge[3].dis = dis(p2 ,p3);
sort(edge + 1 ,edge + 3 + 1 ,campp);
if(
edge[1].dis * edge[1].dis + edge[2].dis * edge[2].dis <= edge[3].dis * edge[3].dis)
{

O.x = (edge[3].A.x + edge[3].B.x) / 2;
O.y = (edge[3].A.y + edge[3].B.y) / 2; R = edge[3].dis / 2;
}
else
{

Line L1 = Line((p1 + p2)/2 ,Normal(p1 - p2),1);
Line L2 = Line((p1 + p3)/2 ,Normal(p1 - p3),1);
O = GetLineIntersection(L1 ,L2);
R = dis(O ,p1);
}
double
diss = dis(p ,O);
if(
diss <= R) printf("Case #%d: Danger\n" ,cas ++);
else
printf("Case #%d: Safe\n" ,cas ++);
}
return
0;
}

hdu4720 三角形的外接圆的更多相关文章

  1. HDU4720+三角形外接圆

    /* 几何 求给定三角形的外接圆圆心 方法:求解二元方程组 */ #include<stdio.h> #include<string.h> #include<math.h ...

  2. CAD:计算三角形的外接圆圆心

    条件:三个定点不共线

  3. poj1266Cover an Arc(三角形外接圆)

    链接 求出三角形的外接圆,通过圆心和半径可以知道这个圆的上下左右最远点,分别判断这个四个点跟弧的两端点A,B的关系,假如判断P点,弧内给出点为C,判断PC是否与AB相交即可判断出P是否在弧上. 精度问 ...

  4. POJ 1329 三角外接圆

    Circle Through Three Points Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3169   Acce ...

  5. poj 1090:The Circumference of the Circle(计算几何,求三角形外心)

    The Circumference of the Circle Time Limit: 2 Seconds      Memory Limit: 65536 KB To calculate the c ...

  6. Delaunay剖分与平面欧几里得距离最小生成树

    这个东西代码我是对着Trinkle的写的,所以就不放代码了.. Delaunay剖分的定义: 一个三角剖分是Delaunay的当且仅当其中的每个三角形的外接圆内部(不包括边界)都没有点. 它的存在性是 ...

  7. XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg

    A. Avengers, The 留坑. B. Black Widow 将所有数的所有约数插入set,然后求mex. #include<bits/stdc++.h> using names ...

  8. Delaunay Triangulation in OpenCascade

    Delaunay Triangulation in OpenCascade eryar@163.com 摘要:本文简要介绍了Delaunay三角剖分的基础理论,并使用OpenCascade的三角剖分算 ...

  9. 探索性思维——How to Solve It

    我觉得这篇文章和什么都能扯上点关系,比如编程. 很多人已经讨论过数学与编程的关系了,这里不想过多探讨,只是简单提一下:有些人把数学贬低地一文不值,认为做一般的应用软件用不到数学:而有些人则把数学拔高到 ...

随机推荐

  1. [源码分析] 消息队列 Kombu 之 启动过程

    [源码分析] 消息队列 Kombu 之 启动过程 0x00 摘要 本系列我们介绍消息队列 Kombu.Kombu 的定位是一个兼容 AMQP 协议的消息队列抽象.通过本文,大家可以了解 Kombu 是 ...

  2. roarctf_2019_realloc_magic

    目录 roarctf_2019_realloc_magic 总结 题目分析 checksec 函数分析 解题思路 初步解题思路 存在的问题 问题解决方案 最终解决思路 编写exp exp说明 roar ...

  3. 不用任何框架,Java 就能实现定时任务的 3 种方法!

    是的,不用任何框架,用我们朴素的 Java 编程语言就能实现定时任务. 今天,栈长就介绍 3 种实现方法,教你如何使用 JDK 实现定时任务! 1. sleep 这也是我们最常用的 sleep 休眠大 ...

  4. The Red Button

    The Red Button 问题 问题描述 Piegirl终于发现了红色按钮,你现在还剩最后一个机会去改变这个结局.这个按钮下面的电路由n个从0到n-1编号节点组成.为了关闭这个按钮,这n个节点必须 ...

  5. 前端学习 node 快速入门 系列 —— 模块(module)

    其他章节请看: 前端学习 node 快速入门 系列 模块(module) 模块的导入 核心模块 在 初步认识 node 这篇文章中,我们在读文件的例子中用到了 require('fs'),在写最简单的 ...

  6. [POJ2828] Buy Tickets(待续)

    [POJ2828] Buy Tickets(待续) 题目大意:多组测试,每组给出\(n\)条信息\((a,b)\),表示\(b\)前面有\(a\)个人,顺序靠后的信息优先级高 Solution.1 由 ...

  7. go调用python命令行参数过量报错python.exe: The filename or extension is too long.的解决方法

    当我们在调用python时,如果传入的参数数据量过大时会报错 python.exe: The filename or extension is too long. 这时候我们的解决办法是放弃传参,将想 ...

  8. 前端学习 node 快速入门 系列 —— 服务端渲染

    其他章节请看: 前端学习 node 快速入门 系列 服务端渲染 在简易版 Apache一文中,我们用 node 做了一个简单的服务器,能提供静态资源访问的能力. 对于真正的网站,页面中的数据应该来自服 ...

  9. 扩展欧几里得算法(EXGCD)学习笔记

    0.前言 相信大家对于欧几里得算法都已经很熟悉了.再学习数论的过程中,我们会用到扩展欧几里得算法(exgcd),大家一定也了解过.这是本蒟蒻在学习扩展欧几里得算法过程中的思考与探索过程. 1.Bézo ...

  10. 攻防世界 reverse 2ex1

    2ex1 CISCN-2018-Quals mark 1 import base64 2 3 std_base= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk ...