• HDU 4720 Naive and Silly Muggles (简单计算几何)


    Naive and Silly Muggles

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


    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
     
    Recommend
    zhuyuanchen520
     

    首先是找出一个最小的圆来覆盖三个点。

    圆心要么是三条线段的中点,或者三角形的外心,很容易找出来。‘

    然后判断点是否在圆外就可以了

      1 /* ***********************************************
      2 Author        :kuangbin
      3 Created Time  :2013-9-11 13:17:28
      4 File Name     :2013-9-111005.cpp
      5 ************************************************ */
      6 
      7 #include <stdio.h>
      8 #include <string.h>
      9 #include <iostream>
     10 #include <algorithm>
     11 #include <vector>
     12 #include <queue>
     13 #include <set>
     14 #include <map>
     15 #include <string>
     16 #include <math.h>
     17 #include <stdlib.h>
     18 #include <time.h>
     19 using namespace std;
     20 const double eps = 1e-8;
     21 int sgn(double x)
     22 {
     23     if(fabs(x) < eps)return 0 ;
     24     if ( x < 0)return -1;
     25     else return 1;
     26 }
     27 struct Point
     28 {
     29     double x,y;
     30     Point(double _x = 0, double _y = 0)
     31     {
     32         x = _x;
     33         y = _y;
     34     }
     35     Point operator -(const Point &b)const
     36     {
     37         return Point(x-b.x,y-b.y);
     38     }
     39     double operator ^(const Point &b)const
     40     {
     41         return x*b.y - y*b.x;
     42     }
     43     void input()
     44     {
     45         scanf("%lf%lf",&x,&y);
     46     }
     47 };
     48 double dist(Point a,Point b)
     49 {
     50     return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
     51 }
     52 
     53 //过三点求圆心坐标
     54 Point waixin(Point a,Point b,Point c)
     55 {
     56     double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2;
     57     double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2;
     58     double d = a1*b2 - a2*b1;
     59     return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 -a2*c1)/d);
     60 }
     61 
     62 
     63 int main()
     64 {
     65     //freopen("in.txt","r",stdin);
     66     //freopen("out.txt","w",stdout);
     67     int T;
     68     int iCase = 0;
     69     Point p[4];
     70     scanf("%d",&T);
     71     while(T--)
     72     {
     73         iCase++;
     74         for(int i = 0;i < 4;i++)
     75             p[i].input();
     76         Point res;
     77         double tmp = 1e20;
     78         for(int i = 0;i < 3;i++)
     79         {
     80             Point t = Point((p[i].x+p[(i+1)%3].x)/2,(p[i].y+p[(i+1)%3].y)/2);
     81             double dd = max(dist(p[0],t),max(dist(p[1],t),dist(p[2],t)));
     82             if(dd < tmp)
     83             {
     84                 tmp = dd;
     85                 res = t;
     86             }
     87         }
     88         if(sgn( (p[1]-p[0])^(p[2]-p[0]) ) != 0)
     89         {
     90             Point t = waixin(p[0],p[1],p[2]);
     91             double dd = max(dist(p[0],t),max(dist(p[1],t),dist(p[2],t)));
     92             if(dd < tmp)
     93             {
     94                 tmp = dd;
     95                 res = t;
     96             }
     97 
     98         }
     99         printf("Case #%d: ",iCase);
    100         if(sgn(tmp - dist(res,p[3])) >= 0)
    101             printf("Danger
    ");
    102         else printf("Safe
    ");
    103     }
    104     return 0;
    105 }
  • 相关阅读:
    应用安全-Web安全-越权漏洞整理
    操作系统
    接码平台 | 临时邮箱生成网站
    shell反弹/端口转发/端口映射/内网穿透/代理/SSH中转/TLS加密传输/协议转换/DNS防污染/抓包工具整理
    远控CVE整理
    Windows系统CVE整理
    https的了解
    软件设计师备考
    https资料
    基本感觉比较好的书
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3315055.html
Copyright © 2020-2023  润新知