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. [转] 考验你的JavaScript底细

    http://sentsin.com/ 尽管今日的JavaScript已经突飞猛进,但JS的许多特性仍然保留,以下题目并不是有意设坑,许多地方将验证你的JS底细,如果错了一半,请别告诉我你从事前端. ...

  2. linux系统下安装wget。

    我们先安装linux系统比如centos7.1里面有的就没有wget下载工具.wget这个命令就不可以使用. 我们使用 yum -y install wget yum install perl 会出现 ...

  3. android 实现垂直的ProgressBar

    I had recently come across the need for a vertical progress bar but was unable to find a solution us ...

  4. js获取图片高度

    js获取图片高度时经常会获取的图片高度为0,原因是图片未加载完毕.第一次加载时,显示0(火狐等部分浏览器显示24).待加载完毕后,再刷新,显示图片高度258. var oImg = document. ...

  5. [原创] SQLite数据库使用清单(上)

    1. 介绍 1.1 安装 访问 SQLite 下载页面,从 Windows 区下载预编译的二进制文件. 您需要下载 sqlite-shell-win32-*.zip 和 sqlite-dll-win3 ...

  6. 【转】 iOS-Core-Animation-Advanced-Techniques(七)

    高效绘图.图像IO以及图层性能 高效绘图 原文:http://www.cocoachina.com/ios/20150106/10840.html 不必要的效率考虑往往是性能问题的万恶之源. ——Wi ...

  7. WebSocket基于javaweb+tomcat的简易demo程序

    由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪 ...

  8. SGU 222.Little Rooks

    题意: 求在n*n(n<10)的棋盘上放k个车(水平竖直行走)的方案数. Solution SGU220的简化版.直接DP 显然当k>n时,ans=0; f[i][j]代表在前n行放了j个 ...

  9. 【POJ2985】【Treap + 并查集】The k-th Largest Group

    Description Newman likes playing with cats. He possesses lots of cats in his home. Because the numbe ...

  10. 防止iframe嵌套

    如果你哪个页面不想被嵌套 下面js代码可以解决(我的是火狐) 慎用 <script type="text/javascript">          window.on ...