• Naive and Silly Muggles hdu4720


    Naive and Silly Muggles

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 452    Accepted Submission(s): 307


    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 of them are inside or on the border of the circle. And due to save the magic power, circle's area should as smaller as it could be.
    Naive and silly "muggles"(who have no talents in magic) should absolutely not get into the circle, nor even on its border, or they will be in danger.
    Given the position of a muggle, is he safe, or in serious danger?
     
    Input
    The first line has a number T (T <= 10) , indicating the number of test cases.
    For each test case there are four lines. Three lines come each with two integers xi and yi (|xi, yi| <= 10), indicating the three wizards' positions. Then a single line with two numbers qx and qy (|qx, qy| <= 10), indicating the muggle's position.
     
    Output
    For test case X, output "Case #X: " first, then output "Danger" or "Safe".
     
    Sample Input
    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
     
    Sample Output
    Case #1: Danger Case #2: Safe Case #3: Safe
     1 #include <iostream>
     2 #include <string.h>
     3 #include <stdio.h>
     4 #include <math.h>
     5 #include <algorithm>
     6 using namespace std;
     7 double p[4][2],x,y;
     8 void fun()
     9 {
    10     double a=2*(p[0][1]-p[1][1]);
    11     double a1=2*(p[1][1]-p[2][1]);
    12     double b=2*(p[0][0]-p[1][0]);
    13     double b1=2*(p[1][0]-p[2][0]);
    14     double c=p[0][0]*p[0][0]+p[0][1]*p[0][1]-p[1][0]*p[1][0]-p[1][1]*p[1][1];
    15     double c1=p[1][0]*p[1][0]+p[1][1]*p[1][1]-p[2][0]*p[2][0]-p[2][1]*p[2][1];
    16     x=(a1*c-a*c1)/(b*a1-b1*a);
    17     y=(c*b1-c1*b)/(b1*a-b*a1);
    18 }
    19 double dis(int k)
    20 {
    21     double sum;
    22     sum=sqrt((x-p[k][0])*(x-p[k][0])+(y-p[k][1])*(y-p[k][1]));
    23     return sum;
    24 }
    25 int main()
    26 {
    27     int t,i,j,n;
    28     scanf("%d",&t);
    29     for(i=1; i<=t; i++)
    30     {
    31         for(j=0; j<4; j++)scanf("%lf%lf",&p[j][0],&p[j][1]);
    32         printf("Case #%d: ",i);
    33         double a=((p[0][0]-p[1][0])*(p[0][0]-p[1][0])+(p[0][1]-p[1][1])*(p[0][1]-p[1][1]));
    34         double b=((p[2][0]-p[1][0])*(p[2][0]-p[1][0])+(p[2][1]-p[1][1])*(p[2][1]-p[1][1]));
    35         double c=((p[0][0]-p[2][0])*(p[0][0]-p[2][0])+(p[0][1]-p[2][1])*(p[0][1]-p[2][1]));
    36         if(a*a+b*b<c*c)
    37         {
    38             x=(p[0][0]+p[2][0])/2;
    39             y=(p[0][1]+p[2][1])/2;
    40         }
    41         else if(a*a+c*c<b*b)
    42         {
    43             x=(p[1][0]+p[2][0])/2;
    44             y=(p[1][1]+p[2][1])/2;
    45         }
    46         else if(b*b+c*c<a*a)
    47         {
    48             x=(p[0][0]+p[1][0])/2;
    49             y=(p[0][1]+p[1][1])/2;
    50         }
    51         else
    52         {
    53             fun();
    54         }
    55         double di=dis(0);
    56         double di1=dis(3);
    57         if(di<di1)
    58         {
    59             cout<<"Safe"<<endl;
    60         }
    61         else cout<<"Danger"<<endl;
    62     }
    63 }
    View Code
  • 相关阅读:
    大四实习有点晚[转载]
    .net2.0数据绑定语法
    明天要去南京了
    Master & Content Page Relation(Event Ordering)
    在验证中使用图像和声音(ErrorMessage)
    设置FLash透明
    Basic Skill in .net2.0
    教育研究方法
    程序员是如何捕猎大象的[转]
    My lost card
  • 原文地址:https://www.cnblogs.com/ERKE/p/3636988.html
Copyright © 2020-2023  润新知