Naive and Silly Muggles

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

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
 
题意:给三个顶点的坐标,求能覆盖该三个点的最小的圆,若最后输入的点的坐标在圆外输出“Safe”,否则输出“Danger”;
 
第一次做数学题目,开始只想到了外接圆,但没分三角形是什么情况,而且三角形外接圆的圆心和半径貌似不会求;于是乎,搜了一下三角形外接圆的圆心和半径求法。
但是题解里说要讨论三角形的形状,就按这个思路敲得,没想到就1A了。
思路:先把三边长求出来,若三点共线,则最小圆的半径是最长边的1/2,否则根据三边判断三角形的形状,并找出最长边记录最长边的端点;
1>若是直角三角形或钝角三角形,最小圆的半径是最长边的1/2,
2>若是锐角三角形,最小圆就是外接圆,找出外接圆的圆心,圆心到任意顶点的距离即为半径;
最后比较最小圆的半径和圆心到那点的距离;
 
 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std; struct node
{
double x,y;
} point[];
double disA_B,disA_C,disB_C,Maxdis;//分别记录三边长和最长边
int a,b;//记录最长边的两个端点
double center_x,center_y;//最小圆的圆心坐标
double d;//记录圆心到该点的距离,与半径比较;
double radiu;//锐角三角形外接圆半径; void Distance()
{
disA_B = sqrt((point[].x-point[].x)*(point[].x-point[].x)+
(point[].y-point[].y)*(point[].y-point[].y));
disA_C = sqrt((point[].x-point[].x)*(point[].x-point[].x)+
(point[].y-point[].y)*(point[].y-point[].y));
disB_C = sqrt((point[].x-point[].x)*(point[].x-point[].x)+
(point[].y-point[].y)*(point[].y-point[].y)); if(disA_B >= disA_C && disA_B >= disB_C)
{
Maxdis = disA_B;
a = ;
b = ;
}
if(disA_C >= disA_B && disA_C >= disB_C)
{
Maxdis = disA_C;
a = ;
b = ;
}
if(disB_C >= disA_B && disB_C >= disA_C)
{
Maxdis = disB_C;
a = ;
b = ;
} }
//计算圆心到顶点的距离
double check(double x1,double y1,double x2,double y2)
{
double d;
d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
return d;
}
//判断三角形类型
int judge(double r1, double r2,double r3)
{
double res;
res = r1*r1+r2*r2-r3*r3;
if(res <= )
return true;//钝角或直角三角形
else return false;//锐角三角形
} int main()
{
int test;
scanf("%d",&test);
for(int t = ; t <= test; t++)
{
for(int i = ; i < ; i++)
scanf("%lf %lf",&point[i].x,&point[i].y); Distance(); printf("Case #%d: ",t); //三点在一条直线上,圆心在最长边的1/2处;
if(point[].x==point[].x && point[].x==point[].x)
{
center_x = (point[a].x+point[b].x)/2.0;
center_y = point[a].y;
d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,Maxdis/2.0);
if(d > Maxdis/2.0)
printf("Safe\n");
else printf("Danger\n");
//printf("在一条直线上\n");
}
else if(point[].y==point[].y && point[].y==point[].y)
{
center_x = point[a].x;
center_y = (point[a].y+point[b].y)/2.0;
d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,Maxdis/2.0);
if(d > Maxdis/2.0)
printf("Safe\n");
else printf("Danger\n");
//printf("在一条直线上\n");
} //钝角或直角三角形,圆心是最长边的1/2处,半径是最长边的一半;
else if(judge(disA_B,disA_C,disB_C) || judge(disA_B,disB_C,disA_C) || judge(disA_C,disB_C,disA_B))
{
center_x = (point[a].x+point[b].x)/2.0;
center_y = (point[a].y+point[b].y)/2.0;
d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,Maxdis/2.0);
if(d > Maxdis/2.0)
printf("Safe\n");
else printf("Danger\n");
//printf("是直角或钝角\n");
} //锐角三角形,圆心是外接圆的圆心;
else if(!judge(disA_B,disA_C,disB_C) && !judge(disA_B,disB_C,disA_C) && !judge(disA_C,disB_C,disA_B))
{
center_x = ;
center_y = ;
double x1 = point[].x;
double x2 = point[].x;
double x3 = point[].x;
double y1 = point[].y;
double y2 = point[].y;
double y3 = point[].y; center_x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(*(x3-x1)*(y2-y1)-*((x2-x1)*(y3-y1)));
center_y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(*(y3-y1)*(x2-x1)-*((y2-y1)*(x3-x1)));
radiu = sqrt((point[].x-center_x)*(point[].x-center_x)+(point[].y-center_y)*(point[].y-center_y)); d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,radiu);
if(d > radiu)
printf("Safe\n");
else printf("Danger\n");
//printf("是锐角\n"); } }
return ;
}
 
 三角形外接圆模板

 void  circle_center(point[])
{
double x1,x2,x3,y1,y2,y3;
double radiu;//外接圆半径
double x = ;
double y = ; x1 = point[].x;
x2 = point[].x;
x3 = point[].x;
y1 = point[].y;
y2 = point[].y;
y3 = point[].y; //圆心坐标(x,y);
x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(*(x3-x1)*(y2-y1)-*((x2-x1)*(y3-y1)));
y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(*(y3-y1)*(x2-x1)-*((y2-y1)*(x3-x1)));
//半径
radiu = sqrt((point[].x - x)*(point[].x - x) + (point[].y - y)*(point[].y - y));
}
 
 

Naive and Silly Muggles (计算几何)的更多相关文章

  1. ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)

    Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...

  2. 计算几何 HDOJ 4720 Naive and Silly Muggles

    题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/a ...

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

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  4. Naive and Silly Muggles

    Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...

  5. HDU 4720 Naive and Silly Muggles (外切圆心)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  6. Naive and Silly Muggles hdu4720

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  7. HDU-4720 Naive and Silly Muggles 圆的外心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 先两两点之间枚举,如果不能找的最小的圆,那么求外心即可.. //STATUS:C++_AC_0M ...

  8. HDU 4720 Naive and Silly Muggles 2013年四川省赛题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 题目大意:给你四个点,用前三个点绘制一个最小的圆,而这三个点必须在圆上或者在圆内,判断最一个点如 ...

  9. HDU 4720 Naive and Silly Muggles 平面几何

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...

随机推荐

  1. 搬移到GitHub Page啦~

    GitHub: https://github.com/BOT-Man-JL/ Page: https://BOT-Man-JL.github.io/

  2. Servlet创建、编译、部署、运行

    最近在做一个通过Servlet实现后台批量接收上传文件的东西,现将Servlet的开发.运行配置.调用记录下来.我们以最简单的FileUpload为例,目前所有的http协议相关的Servlet均继承 ...

  3. 安装zookeeper时候,可以查看进程启动,但是状态显示报错:Error contacting service. It is probably not running

    安装zookeeper-3.3.2的时候,启动正常没报错,但zkServer.sh status查看状态的时候却出现错误,如下: JMX enabled by defaultUsing config: ...

  4. 原生JS添加节点方法与jQuery添加节点方法的比较及总结

    一.首先构建一个简单布局,来供下边讲解使用 1.HTML部分代码: <div id="div1">div1</div> <div id="d ...

  5. PHP 解决未定义变量报错

    在PHP中 有时候会出现 Notice: Undefined index: sid in D:\Apache Group\Apache2\htdocs\php_mobile\mobile\chao\s ...

  6. For and While loop choice.

    /* Difference between 'for' and 'while'. We can transform everything between 'for' and 'while'. if t ...

  7. 关于百度 UEditor的使用

    1.文件路径的配置: 注意:在页面上需要指定editor文件所在的路径,否则报错 后面有时间,再说说 kindEditor和  bootstrap3的summernote的  Editor,  fck ...

  8. 【转】iOS开发之各种动画各种页面切面效果

    原文: http://www.cnblogs.com/ludashi/p/4160208.html?utm_source=tuicool 因工作原因,有段时间没发表博客了,今天就发表篇博客给大家带来一 ...

  9. 【BZOJ2752】【线段树】高速公路

    Description Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站. Y901高速公路是一条由N-1段路以及N个 ...

  10. [FindBugs分析记录]Redundant nullcheck of o,which is known to be non-null

    官网解释: This method contains a redundant check of a known non-null value against the constant null. 这种 ...