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. [转] 怎样在Ubuntu 14.04中搭建gitolite git服务器

    相比gitosis,gitolite的功能更为强大,支持对权限的细分控制,学习一下在最新版 的ubuntu 14.04 LTS中搭建gitolite服务器是非常有必要的,嘿嘿,一会属于我们自己的Git ...

  2. Linux squid 安装配置

    linux 代理软件 squid 查看是否安装squid   以上信息表明,本机是已经安装了此软件了 如果没有显示说明没有安装,则可以使用yum工具来安装   安装完软件后我们接着开始配置squid代 ...

  3. 2进制,16进制,BCD,ascii,序列化对象相互转换

    public final static char[] BToA = "0123456789abcdef".toCharArray() ; 1.16进制字符串转为字节数组 /** * ...

  4. 23、Javascript DOM

    DOM Document Object Model(文档对象模型)定义了html和xml的文档标准. DOM 节点树 <html> <head> <title>DO ...

  5. Java实现ajax

    jsp端的代码,sucess:function(){} 里面就是返回的处理 function ChangeTime(){ alert("www"); var startYmd = ...

  6. 关于一些Android冷知识

    1. 在Android4.0以后,EditText就由以前的输入框变成了一条划线的输入方式,如需要变为老版本的,只需在layout里面引入代码: android:background="@a ...

  7. 开源的Android开发框架-------PowerFramework使用心得(四)数据库管理DBFarmer

    DBFarmer是PowerFramework数据库管理工具的集合. 可以进行对象的存储,添加了setter和getter的参数会被收录到数据库中,每个参数作为一个项,int类型的id或_id会被作为 ...

  8. WCF,WebAPI,WCFREST和WebService的区别

    Web ServiceIt is based on SOAP and return data in XML form.It support only HTTP protocol.It is not o ...

  9. 灵活运用绑定变量---declare匿名块使用绑定变量

    declare        type cur01 is ref cursor;     v_cur cur01;        v_match123 varchar2(2000);        v ...

  10. 非注解SpringMVC

    <!-- SpringMVC前端控制器 --> <servlet> <servlet-name>springmvc</servlet-name> < ...