zoukankan      html  css  js  c++  java
  • 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;
    }

     
  • 相关阅读:
    jquery 筛选元素(1)
    jquery操作元素的位置
    jquery 操作css 选择器
    jquery 操作css 尺寸
    jquery 标签中的属性操作
    jquery基本选择器
    jquery表单属性筛选元素
    jquery属性值选择器
    jquery 层级选择器
    jquery的基本选择器
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3317652.html
Copyright © 2011-2022 走看看