Hdoj 4720 Naive and Silly muggles triangle circumscribed circle

Source: Internet
Author: User


When it is obtuse triangle, the longest edge is the smallest circle with a diameter.

Otherwise, seek the circumscribed circle of the triangle

Naive and Silly MugglesTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): Accepted submission (s): 451


Problem Descriptionthree Wizards is doing a experiment. To avoid from bothering, the A special magic is set around them. The Magic forms a circle, which covers those three wizards, in other words, all of them is inside or on the border of the Circle. And due to save the magic Power, Circle's area should as smaller as it could is.
Naive and silly "Muggles" (who has no talents in magic) should absolutely does get into the circle, nor even on its border, Or they'll is in danger.
Given the position of a Muggle, is he safe, or in serious danger?
Inputthe first line has a number T (T <=), indicating the number of test cases.
For the test case there is four lines. Three lines come each with a integers xi and Yi (|xi, yi| <=), indicating the three wizards ' positions. Then a numbers qx and qy (|QX, qy| <=), indicating the Muggle ' s position.
Outputfor test Case X, output ' case #X: ' First, then output ' Danger ' or ' Safe '.
Sample Input
30 02 01 21-0.50 02 01 21-0.60 03 01 11-1.5

Sample Output
Case #1: dangercase #2: safecase #3: Safe

Source2013 ACM/ICPC Asia Regional online--warmup2
Recommendzhuyuanchen520 | We have carefully selected several similar problems for you:5157 5156 5155 5154 5153
Statistic | Submit | Discuss | Note


/* ***********************************************author:ckbosscreated time:2015 January 07 Wednesday 23:26 30 seconds 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) {}};d ouble 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);        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 triangle circumscribed circle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.