题意:

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

思路:

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


  1. #include <cstdio>
  2. #include <cmath>
  3. #include <algorithm>
  4. #define maxn 60
  5. #define eps 1e-7
  6. using namespace std;
  7. int dcmp(double x) //控制精度
  8. {
  9. if(fabs(x)<eps) return 0;
  10. else return x<0?-1:1;
  11. }
  12. double toRad(double deg) //角度转弧度
  13. {
  14. return deg/180.0*acos(-1.0);
  15. }
  16. struct Point
  17. {
  18. double x,y;
  19. Point(){}
  20. Point(double x,double y):x(x),y(y) {}
  21. void input()
  22. {
  23. scanf("%lf %lf",&x,&y);
  24. }
  25. };
  26. typedef Point Vector;
  27. Vector operator+( Vector A, Vector B ) //向量加
  28. {
  29. return Vector( A.x + B.x, A.y + B.y );
  30. }
  31. Vector operator-(Vector A,Vector B) //向量减
  32. {
  33. return Vector( A.x - B.x, A.y - B.y );
  34. }
  35. Vector operator*( Vector A, double p ) //向量数乘
  36. {
  37. return Vector( A.x * p, A.y * p );
  38. }
  39. Vector operator/( Vector A, double p ) //向量数除
  40. {
  41. return Vector( A.x / p, A.y / p );
  42. }
  43. bool operator<(const Point& A, const Point& B ) //两点比较
  44. {
  45. return dcmp( A.x - B.x ) < 0 || ( dcmp( A.x - B.x ) == 0 && dcmp( A.y - B.y ) < 0 );
  46. }
  47. bool operator==( const Point& a, const Point& b ) //两点相等
  48. {
  49. return dcmp( a.x - b.x ) == 0 && dcmp( a.y - b.y ) == 0;
  50. }
  51. struct Line
  52. {
  53. Point s,e;
  54. Vector v;
  55. Line() {}
  56. Line(Point s,Point v,int type)://法向量式
  57. s(s),v(v){}
  58. Line(Point s,Point e):s(s),e(e)//两点式
  59. {v=e-s;}
  60. };
  61. double Dot(Vector A,Vector B)//向量点乘
  62. {
  63. return A.x*B.x+A.y*B.y;
  64. }
  65. double Length(Vector A)//向量模
  66. {
  67. return sqrt(Dot(A,A));
  68. }
  69. double Angle(Vector A,Vector B)//向量夹角
  70. {
  71. return acos(Dot(A,B)/Length(A)/Length(B));
  72. }
  73. double Cross(Vector A,Vector B)//向量叉积
  74. {
  75. return A.x*B.y-A.y*B.x;
  76. }
  77. double Area2(Point A,Point B,Point C )//向量有向面积
  78. {
  79. return Cross(B-A,C-A);
  80. }
  81. double Dist(Point A,Point B)
  82. {
  83. return Length(A-B);
  84. }
  85. Vector Rotate(Vector A, double rad)//向量逆时针旋转
  86. {
  87. return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
  88. }
  89. Vector Normal(Vector A)//向量单位法向量
  90. {
  91. double L=Length(A);
  92. return Vector(-A.y/L,A.x/L);
  93. }
  94. Point GetLineIntersection(Line l1,Line l2)//两直线交点
  95. {
  96. Point P=l1.s;
  97. Vector v=l1.v;
  98. Point Q=l2.s;
  99. Vector w=l2.v;
  100. Vector u=P-Q;
  101. double t=Cross(w,u)/Cross(v,w);
  102. return P+v*t;
  103. }
  104. double DistanceToLine(Point P,Line L)//点到直线的距离
  105. {
  106. Point A,B;
  107. A=L.s,B=L.e;
  108. Vector v1=B-A,v2=P-A;
  109. return fabs(Cross(v1,v2))/Length(v1);
  110. }
  111. double DistanceToSegment(Point P, Line L)//点到线段的距离
  112. {
  113. Point A,B;
  114. A=L.s,B=L.e;
  115. if(A==B) return Length(P-A);
  116. Vector v1=B-A,v2=P-A,v3=P-B;
  117. if (dcmp(Dot(v1,v2))<0) return Length(v2);
  118. else if (dcmp(Dot(v1,v3))>0) return Length(v3);
  119. else return fabs(Cross(v1,v2)) / Length(v1);
  120. }
  121. Point GetLineProjection(Point P,Line L)// 点在直线上的投影
  122. {
  123. Point A,B;
  124. A=L.s,B=L.e;
  125. Vector v=B-A;
  126. return A+v*(Dot(v,P-A)/Dot(v,v));
  127. }
  128. bool OnSegment(Point p,Line l)//点在线段上包括端点
  129. {
  130. Point a1=l.s;
  131. Point a2=l.e;
  132. return dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dist(p,a1)+Dist(p,a2)-Dist(a1,a2))==0;
  133. }
  134. bool Paralled(Line l1,Line l2)//直线平行
  135. {
  136. return dcmp(Cross(l1.e-l1.s,l2.e-l2.s))==0;
  137. }
  138. bool SegmentProperIntersection(Line l1,Line l2)//线段相交
  139. {
  140. if(Paralled(l1,l2))
  141. {
  142. return false;
  143. }
  144. Point t=GetLineIntersection(l1,l2);
  145. if(OnSegment(t,l1))
  146. {
  147. return true;
  148. }
  149. return false;
  150. }
  151. int ConvexHull(Point *p,int n,Point *ch) //求凸包
  152. {
  153. sort(p,p+n);
  154. int m=0;
  155. for ( int i = 0; i < n; ++i )
  156. {
  157. while ( m > 1 && Cross( ch[m - 1] - ch[m - 2], p[i] - ch[m - 2] ) <= 0 ) --m;
  158. ch[m++] = p[i];
  159. }
  160. int k = m;
  161. for ( int i = n - 2; i >= 0; --i )
  162. {
  163. while ( m > k && Cross( ch[m - 1] - ch[m - 2], p[i] - ch[m - 2] ) <= 0 ) --m;
  164. ch[m++] = p[i];
  165. }
  166. if ( n > 1 ) --m;
  167. return m;
  168. }
  169. double PolygonArea(Point *p,int n) //多边形有向面积
  170. {
  171. double area=0;
  172. for (int i=1;i<n-1;++i)
  173. area+=Cross(p[i]-p[0],p[i+1]-p[0]);
  174. return area/2.0;
  175. }
  176. double dis(Point A ,Point B)
  177. {
  178. double tmp = (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
  179. return sqrt(tmp);
  180. }
  181. typedef struct
  182. {
  183. double dis;
  184. Point A ,B;
  185. }EDGE;
  186.  
  187. EDGE edge[5];
  188. bool campp(EDGE a ,EDGE b)
  189. {
  190. return a.dis < b.dis;
  191. }
  192. int main ()
  193. {
  194. int t ,i ,cas = 1;
  195. Point p1 ,p2 ,p3 ,p;
  196. Point O;
  197. double R;
  198. scanf("%d" ,&t);
  199. while(t--)
  200. {
  201. scanf("%lf %lf" ,&p1.x ,&p1.y);
  202. scanf("%lf %lf" ,&p2.x ,&p2.y);
  203. scanf("%lf %lf" ,&p3.x ,&p3.y);
  204. scanf("%lf %lf" ,&p.x ,&p.y);
  205. edge[1].A = p1 ,edge[1].B = p2;
  206. edge[2].A = p1 ,edge[2].B = p3;
  207. edge[3].A = p2 ,edge[3].B = p3;
  208. edge[1].dis = dis(p1 ,p2);
  209. edge[2].dis = dis(p1 ,p3);
  210. edge[3].dis = dis(p2 ,p3);
  211. sort(edge + 1 ,edge + 3 + 1 ,campp);
  212. if(edge[1].dis * edge[1].dis + edge[2].dis * edge[2].dis <= edge[3].dis * edge[3].dis)
  213. {
  214. O.x = (edge[3].A.x + edge[3].B.x) / 2;
  215. O.y = (edge[3].A.y + edge[3].B.y) / 2;
  216.  
  217. R = edge[3].dis / 2;
  218. }
  219. else
  220. {
  221. Line L1 = Line((p1 + p2)/2 ,Normal(p1 - p2),1);
  222. Line L2 = Line((p1 + p3)/2 ,Normal(p1 - p3),1);
  223. O = GetLineIntersection(L1 ,L2);
  224. R = dis(O ,p1);
  225. }
  226. double diss = dis(p ,O);
  227. if(diss <= R) printf("Case #%d: Danger\n" ,cas ++);
  228. else printf("Case #%d: Safe\n" ,cas ++);
  229. }
  230. return 0;
  231. }

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. HDOJ-1024(动态规划+滚动数组)

    Max Sum Plus Plus HDOJ-1024 动态转移方程:dp[i][j]=max(dp[i][j-1]+a[j],max(dp[i-1][k])+a[j]) (0<k<j) ...

  2. 漏洞复现-CVE-2014-3120-ElasticSearch 命令执行漏洞

        0x00 实验环境 攻击机:Win 10 靶机也可作为攻击机:Ubuntu18 (docker搭建的vulhub靶场) 0x01 影响版本 < ElasticSearch 1.2的版本 ...

  3. Java基础语法学习

    Java基础语法学习 1. 注释 单行注释: //单行注释 多行注释: /*多行注释 多行注释 多行注释 多行注释 */ 2. 关键字与标识符 关键字: Java所有的组成部分都需要名字.类名.变量名 ...

  4. cpu缓存和volatile

    目录 CPU缓存的由来 CPU缓存的概念 CPU缓存的意义 缓存一致性协议-MESI协议 Store Buffers Store Forwarding Memory Barriers Invalida ...

  5. Apache配置 2.用户认证

    1.用户认证用来对某些目录中的网页进行访问控制,当用户访问这些页面的时候需要输入用户名和密码进行认证. 2. 配置: # vim /usr/local/apache2.4/conf/extra/htt ...

  6. android分析之Binder 02

    分析Java层的ServiceManager,看看Binder在Java层是如何实现的. public final class ServiceManager { private static fina ...

  7. VS添加dll引用

    直接添加(CADImport.dll) 手动添加 (sgcadexp.dll) 直接放到项目bin的目录下

  8. PTA 二叉树的三种遍历(先序、中序和后序)

    6-5 二叉树的三种遍历(先序.中序和后序) (6 分)   本题要求实现给定的二叉树的三种遍历. 函数接口定义: void Preorder(BiTree T); void Inorder(BiTr ...

  9. Redis入门到放弃系列-redis数据类型

    Redis数据类型? Redis 提供一些常用的数据类型:Strings.Lists.Sets.Sorted sets.Hashes.Arrays.Bitmap.Streams Strings(字符串 ...

  10. 用 Go + WebSocket 快速实现一个 chat 服务

    前言 在 go-zero 开源之后,非常多的用户询问是否可以支持以及什么时候支持 websocket,终于在 v1.1.6 里面我们从框架层面让 websocket 的支持落地了,下面我们就以 cha ...