hdu4720Naive and Silly Muggles

链接

一直理解的最小覆盖圆就是外接圆。。原来还要分钝角和锐角。。。

钝角的话就为最长边的中点,对于这题分别枚举一下外接圆以及中点的圆,判一下是不是在园外。

  1 #include <iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<stdlib.h>
  6 #include<vector>
  7 #include<cmath>
  8 #include<queue>
  9 #include<set>
 10 using namespace std;
 11 #define N 100000
 12 #define LL long long
 13 #define INF 0xfffffff
 14 const double eps = 1e-8;
 15 const double pi = acos(-1.0);
 16 const double inf = ~0u>>2;
 17 struct Point
 18 {
 19     double x,y;
 20     Point (double x=0,double y =0):x(x),y(y){}
 21 }p[4];
 22 struct Circle
 23 {
 24     Point center;
 25     double r;
 26 };
 27 typedef Point pointt;
 28 pointt operator - (Point a,Point b)
 29 {
 30     return Point(a.x-b.x,a.y-b.y);
 31 }
 32 int dcmp(double x)
 33 {
 34     if(fabs(x)<eps) return 0;
 35     return x<0?-1:1;
 36 }
 37 double dis(Point a)
 38 {
 39     return a.x*a.x+a.y*a.y;
 40 }
 41 double cross(Point a,Point b)
 42 {
 43     return a.x*b.y-a.y*b.x;
 44 }
 45 double area()
 46 {
 47     return fabs(cross(p[1]-p[2],p[2]-p[3]))/2;
 48 }
 49 struct Circle Circumcircle()
 50 {
 51     Circle tmp;
 52     double a,b,c,c1,c2;
 53     double xa,ya,xb,yb,xc,yc;
 54     a = sqrt(dis(p[3]-p[1]));
 55     b = sqrt(dis(p[1]-p[2]));
 56     c = sqrt(dis(p[2]-p[3]));
 57     //¸ù¾Ýs = a*b*c/R/4£¬Çó°ë¾¶
 58     tmp.r = (a*b*c)/(area()*4.0);
 59     xa = p[3].x;
 60     ya = p[3].y;
 61     xb = p[1].x;
 62     yb = p[1].y;
 63     xc = p[2].x;
 64     yc = p[2].y;
 65     c1 = (dis(p[3])-dis(p[1]))/2;
 66     c2 = (dis(p[3])-dis(p[2]))/2;
 67     tmp.center.x = (c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb));
 68     tmp.center.y = (c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb));
 69     return tmp;
 70 }
 71 int main()
 72 {
 73     int t,i;
 74     cin>>t;
 75     int kk = 0;
 76     while(t--)
 77     {
 78         for(i = 1 ;i <= 3 ; i++)
 79         scanf("%lf%lf",&p[i].x,&p[i].y);
 80         Circle cc = Circumcircle();
 81         Point pp;
 82         scanf("%lf%lf",&pp.x,&pp.y);
 83         double r = cc.r;
 84         r*=r;
 85         printf("Case #%d: ",++kk);
 86         if(dis(pp-cc.center)>r)
 87         {
 88             puts("Safe");
 89             continue;
 90         }
 91         r = dis(p[1]-p[2])/4;
 92         cc.center.x = (p[1].x+p[2].x)/2;
 93         cc.center.y = (p[1].y+p[2].y)/2;
 94         if(dcmp(dis(p[3]-cc.center)-r)<=0&&dcmp(dis(pp-cc.center)-r)>0)
 95         {
 96             puts("Safe");
 97             continue;
 98         }
 99         r = dis(p[1]-p[3])/4;
100         cc.center.x = (p[1].x+p[3].x)/2;
101         cc.center.y = (p[1].y+p[3].y)/2;
102         if(dcmp(dis(p[2]-cc.center)-r)<=0&&dcmp(dis(pp-cc.center)-r)>0)
103         {
104             puts("Safe");
105             continue;
106         }
107         r = dis(p[3]-p[2])/4;
108         cc.center.x = (p[3].x+p[2].x)/2;
109         cc.center.y = (p[3].y+p[2].y)/2;
110         if(dcmp(dis(p[1]-cc.center)-r)<=0&&dcmp(dis(pp-cc.center)-r)>0)
111         {
112             puts("Safe");
113             continue;
114         }
115         puts("Danger");
116     }
117     return 0;
118 }

hdu4720Naive and Silly Muggles

时间: 2024-08-11 00:44:22

hdu4720Naive and Silly Muggles的相关文章

ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)

Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set around them. The magic forms a circle, which covers those three wizards, in other words, all of them are inside or on the border of the circle. And due

计算几何 HDOJ 4720 Naive and Silly Muggles

题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/archive/2013/09/11/3315055.html */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string

Naive and Silly Muggles(计算几何 判断点是否在三点形成的最小圆内)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set around them. The magic forms a circle, which covers those three wizards, in other words, all

HDU 4720 :Naive and Silly Muggles

题目:HDU 4720 :Naive and Silly Muggles 题目大意:这题的意思是给出三个点, 然后在给出另一个点,问这个点会不会在覆盖前面三个点的最小的圆里面(包括边界), 在里面最输出danger, 如果任何情况下这个点都不在圆里面,那么就输出safe. 解题思路:三个点最小的覆盖的圆是三角形的外接圆,这样的圆面积一定是最小的. 但是相同面积的圆,所在的位置,覆盖的点会是不一样的.例如垂心关于三条边的对称点,以某个对称点为圆心的圆用之前的半径做圆,如果能够覆盖原来的三个点(点可

hdu 4720 Naive and Silly Muggles(几何)

题目链接:hdu 4720 Naive and Silly Muggles 题目大意:给出三点,找出一个圆,要求面积尽量小,并且三点必须在园内,如果可以找到一个圆,使得说第4个点不在圆内则是安全的. 解题思路:面积最小即三个点外切圆,根据三角形两条边的垂直平分线求出圆心.判断第4个点是否在圆内只要计算距离即可. 然后还要考虑说面积和外切圆相同,但是圆心不同的圆. #include <cstdio> #include <cstring> #include <cmath>

HDOJ 4720 Naive and Silly Muggles 三角形外接圆

当是钝角三角形时,就是最长边为直径的圆最小. 否则,求三角形的外接圆 Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 700    Accepted Submission(s): 451 Problem Description Three wizards are doing a exper

2013 成都邀请赛

今年又要打邀请赛了,前段时间做比赛都被虐的够呛.感觉不会再爱了...所以挂了下去年的成都邀请赛的题目.发现简单题还是能切上几道的,可是难题就无能为力了.. .阿门,还是水平差得远啊.. . (ps:近期感觉状态不佳.依靠了队友神勇的发挥. .. Current Time: 2014-05-15 08:43:24 Contest Type: Public Start Time: 2014-05-14 15:10:00 Contest Status: Ended End Time: 2014-05-

TCP Silly Window Syndrome

In the topic describing TCP's Maximum Segment Size (MSS) parameter, I explained the trade-off in determining the optimal size of TCP segments. If segments are too large, we risk having them become fragmented at the IP level. Too small, and we get gre

UVA 1016 - Silly Sort(置换分解+贪心)

UVA 1016 - Silly Sort 题目链接 题意:给定一个序列,数字都不同,每次可以交换两个数字,交换的代价为两数之和,要求出把这个序列变成递增最小代价 思路:利用置换的分解原理,可以把序列的每条循环单独考虑,对于每条循环而言,不断交换肯定每个数字至少会换到一次,再利用贪心的思想,如果每次拿循环中的最小值去置换,那么就是这个最小值会用长度-1次,而剩下的数字各一次,注意这里还有一种可能优的方法,就是先把整个序列中的最小值换到该循环中,等置换完再换出去,两种都考虑进来即可 代码: #in