博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Naive and Silly Muggles
阅读量:4660 次
发布时间:2019-06-09

本文共 3077 字,大约阅读时间需要 10 分钟。

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 x
i and y
i (|x
i, y
i| <= 10), indicating the three wizards' positions. Then a single line with two numbers q
x and q
y (|q
x, q
y| <= 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
题意:给出三个点,求一个包围三个点的最小圆。给定一定点判断是否在圆内
题解:三个点围成三角形如果是锐角或者直角三角形那么最小圆即为外接圆。如果为钝角三角形即为一最大边中点为圆心直径为最大边此时为最小圆
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
struct Point{
 double x;
 double y;
};
struct Traingle{
 struct Point p[3];
};
struct Circle{
 struct Point center;
 double r;
};
double Dis(struct Point p,struct Point q)
{
 double dx=p.x-q.x;
 double dy=p.y-q.y;
 return sqrt(dx*dx+dy*dy);
}
double Area(struct Traingle ct)
{
 return fabs((ct.p[1].x-ct.p[0].x)*(ct.p[2].y-ct.p[0].y)-(ct.p[2].x-ct.p[0].x)*(ct.p[1].y-ct.p[0].y))/2.0;
}
double maxi(double a,double b)
{
 return a>b?a:b;
}
struct Circle CircumCircle(struct Traingle t)
{
 struct Circle tmp;
 int flag=0;
 double a,b,c,c1,c2,tt;
 double xA,yA,xB,yB,xC,yC;
 a=Dis(t.p[0],t.p[1]);
 b=Dis(t.p[1],t.p[2]);
 c=Dis(t.p[2],t.p[0]);
    tt=maxi(c,maxi(a,b));
    if(tt==a)
 {
       if(a*a>b*b+c*c)
    {
     tmp.r=a/2;
     tmp.center.x=(t.p[0].x+t.p[1].x)/2;
     tmp.center.y=(t.p[0].y+t.p[1].y)/2;
     flag=1;
    }
 }
 else if(tt==b)
 {
  if(b*b>a*a+c*c)
  {
   tmp.r=b/2;
   tmp.center.x=(t.p[1].x+t.p[2].x)/2;
   tmp.center.y=(t.p[1].y+t.p[2].y)/2;
   flag=1;
  }
 }
 else if(tt==c)
 {
  if(c*c>a*a+b*b)
  {
   tmp.r=c/2;
   tmp.center.x=(t.p[2].x+t.p[0].x)/2;
   tmp.center.y=(t.p[2].y+t.p[0].y)/2;
   flag=1;
  }
 }
 if(flag==0)
 {
 tmp.r=(a*b*c)/(Area(t)*4.0);
 xA=t.p[0].x;
 yA=t.p[0].y;
 xB=t.p[1].x;
 yB=t.p[1].y;
 xC=t.p[2].x;
 yC=t.p[2].y;
 c1=(xA*xA+yA*yA-xB*xB-yB*yB)/2;
 c2=(xA*xA+yA*yA-xC*xC-yC*yC)/2;
 tmp.center.x=(c1*(yA-yC)-c2*(yA-yB))/((xA-xB)*(yA-yC)-(xA-xC)*(yA-yB));
 tmp.center.y=(c1*(xA-xC)-c2*(xA-xB))/((yA-yB)*(xA-xC)-(yA-yC)*(xA-xB));
 }
 return tmp;
}
int main()
{
    Circle cr;
 Traingle s;
 int i,ca=0;
 int test;
 double a,b;
 scanf("%d",&test);
    while(test--)
 {
  ca++;
  for(i=0;i<3;i++)
  {
   scanf("%lf %lf",&s.p[i].x,&s.p[i].y);
  }
  cr=CircumCircle(s);
  scanf("%lf %lf",&a,&b);
  printf("Case #%d: ",ca);
  if((a-cr.center.x)*(a-cr.center.x)+(b-cr.center.y)*(b-cr.center.y)<=cr.r*cr.r) printf("Danger\n");
  else printf("Safe\n");
 }
 return 0;
}

转载于:https://www.cnblogs.com/ffhuguang/p/3318251.html

你可能感兴趣的文章
POJ 3723
查看>>
Sublime Text 3 及Package Control 安装(附上一个3103可用的Key)
查看>>
基于uFUN开发板的心率计(一)DMA方式获取传感器数据
查看>>
【dp】船
查看>>
oracle, group by, having, where
查看>>
nodejs pm2使用
查看>>
CSS选择器总结
查看>>
sql语句的各种模糊查询语句
查看>>
移动端单屏解决方案
查看>>
web渗透测试基本步骤
查看>>
使用Struts2标签遍历集合
查看>>
angular.isUndefined()
查看>>
第一次软件工程作业(改进版)
查看>>
网络流24题-飞行员配对方案问题
查看>>
引入css的四种方式
查看>>
iOS开发UI篇—transframe属性(形变)
查看>>
LOJ 2537 「PKUWC2018」Minimax
查看>>
使用java中replaceAll方法替换字符串中的反斜杠
查看>>
流量调整和限流技术 【转载】
查看>>
1 线性空间
查看>>