标签:
当是钝角三角形时,就是最长边为直径的圆最小.
否则,求三角形的外接圆
3 0 0 2 0 1 2 1 -0.5 0 0 2 0 1 2 1 -0.6 0 0 3 0 1 1 1 -1.5
Case #1: Danger Case #2: Safe Case #3: Safe
/* *********************************************** Author :CKboss Created Time :2015年01月07日 星期三 23时26分30秒 File Name :HDOJ4720.cpp ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> using namespace std; double eps = 1e-10; int dcmp(double x) { if(fabs(x)<eps) return 0; return (x<0)?-1:1;} struct Point { double x,y; Point(double _x,double _y):x(_x),y(_y){} Point(){} }; Point operator-(Point A,Point B) {return Point(A.x-B.x,A.y-B.y);} struct Circle { Point c; double r; Circle(Point _c,double _r):c(_c),r(_r){} }; double Dot(Point A,Point B) { return A.x*B.x+A.y*B.y; } double Length(Point A) { return sqrt(Dot(A,A)); } Circle CircumscribedClircle(Point p1,Point p2,Point p3) { double Bx=p2.x-p1.x,By=p2.y-p1.y; double Cx=p3.x-p1.x,Cy=p3.y-p1.y; double D=2*(Bx*Cy-By*Cx); double cx=(Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D+p1.x; double cy=(Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D+p1.y; Point p = Point(cx,cy); return Circle(p,Length(p1-p)); } Point p1,p2,p3,pp; bool check(Circle c , Point p) { double l1 = Length(c.c-p); double l2 = c.r; if(dcmp(l1-l2)<=0) return false; return true; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int T_T,cas=1; scanf("%d",&T_T); while(T_T--) { double x,y; scanf("%lf%lf",&x,&y); p1=Point(x,y); scanf("%lf%lf",&x,&y); p2=Point(x,y); scanf("%lf%lf",&x,&y); p3=Point(x,y); scanf("%lf%lf",&x,&y); pp=Point(x,y); // two point on the magic circle printf("Case #%d: ",cas++); /// p1 ... p2 double rrr = Length(p1-p2)/2; Point ppp = Point((p1.x+p2.x)/2,(p1.y+p2.y)/2); Circle ccc = Circle(ppp,rrr); if(check(ccc,p3)==false) { if(check(ccc,pp)==true) puts("Safe"); else puts("Danger"); continue; } /// p2...p3 rrr = Length(p2-p3)/2; ppp = Point((p2.x+p3.x)/2.,(p2.y+p3.y)/2.); ccc = Circle(ppp,rrr); if(check(ccc,p1)==false) { if(check(ccc,pp)==true) puts("Safe"); else puts("Danger"); continue; } /// p1...p3 rrr = Length(p1-p3)/2; ppp = Point((p1.x+p3.x)/2.,(p1.y+p3.y)/2.); ccc = Circle(ppp,rrr); if(check(ccc,p2)==false) { if(check(ccc,pp)==true) puts("Safe"); else puts("Danger"); continue; } /// three point on circle Circle cc = CircumscribedClircle(p1,p2,p3); double len = Length(cc.c-pp); if(dcmp(len-cc.r)<=0) puts("Danger"); else puts("Safe"); } return 0; }
HDOJ 4720 Naive and Silly Muggles 三角形外接圆
标签:
原文地址:http://blog.csdn.net/ck_boss/article/details/42521299