• hdu4720


    Naive and Silly Muggles

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


    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
     
    Source
     
     
    一定要考虑钝角三角形和锐角三角形的区别,利用向量法判断三角形中是否有钝角
     
     

    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<string>
    #include<cstdio>
    using namespace std;

    int main()
    {
        int tes;
        int cas=0;
        double x1,y1,x2,y2,x3,y3,a,b,r2,x,y;
        scanf("%d",&tes);
        while(tes--)
        {
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y);
            if((x2-x1)*(x3-x1)+(y2-y1)*(y3-y1)<0)            //(x1,y1)是钝角
            {
                a=(x3+x2)/2.0,b=(y3+y2)/2.0;
                r2=(a-x2)*(a-x2)+(b-y2)*(b-y2);
            }
            else if((x1-x2)*(x3-x2)+(y1-y2)*(y3-y2)<0)        //(x2,y2)是钝角
            {
                a=(x3+x1)/2.0,b=(y3+y1)/2.0;
                r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
            }
            else if((x1-x3)*(x2-x3)+(y1-y3)*(y2-y3)<0)        //(x3,y3)是钝角
            {
                a=(x2+x1)/2.0,b=(y2+y1)/2.0;
                r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
            }
            else         //三角形是锐角三角形
            {
                a=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2.0*((x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)));
                b=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2.0*((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1)));
                r2=(x1-a)*(x1-a)+(y1-b)*(y1-b);
            }
            if((x-a)*(x-a)+(y-b)*(y-b)<=r2)
                printf("Case #%d: Danger ",++cas);
            else
                printf("Case #%d: Safe ",++cas);
        }
        return 0;
    }

     
  • 相关阅读:
    2020-11-07:已知一个正整数数组,两个数相加等于N并且一定存在,如何找到两个数相乘最小的两个数?
    2020-11-06:go中,谈一下调度器。
    Python2和Python3中urllib库中urlencode的使用注意事项
    python爬虫基础
    python自动抢票
    Movist for Mac 1.4.2 破解版 | Mac上好用的视频播放器有哪些?7 款本地视频播放器实测对比
    前端自动化及优化
    移动端库
    jQuery
    JavaScript
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3317652.html
Copyright © 2020-2023  润新知