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. Fix java version mismatch in windows---stackoverflow

    Question: I have the 64bit version of the jdk installed on windows 7. I installed the 32 bit version ...

  2. Java中ArrayList问题:删除一个ArrayList中的重复元素,注意留意一个问题

    该问题有两种方法: 一 利用两个数组,此法简单,不讨论 二 利用一个数组,从第0个开始依次取元素,并在其后元素中查找是否有该元素,有则删掉后面的重复元素,依次遍历.---但是这种情况要特别注意,当后续 ...

  3. Notepad++在编程使用时的小技巧

    http://blog.csdn.net/freewaywalker/article/details/8010790 为了编程时更快捷和适应个人习惯,我们可以对Notepad++进行一系列的设置,这当 ...

  4. A除以B_2

    本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成立. 输入格式: 输入在1行中依次给出A和B,中间以1空格分隔. 输出格 ...

  5. Objective - C 中NSString (字符串)与C中的字符串转换问题

    NSString是一个常用的类,NSString是原生支持unicode C中的字符串 比如char * a = "hello world";  是utf8类型的, char* d ...

  6. MVC5+EF6 入门完整教程一

    第0课 从0开始 ASP.NET MVC开发模式和传统的WebForm开发模式相比,增加了很多"约定". 直接讲这些 "约定" 会让人困惑,而且东西太多容易忘记 ...

  7. c#中设置按钮Button为透明

    方法一:代码实现 /// <summary> /// 设置透明按钮样式 /// </summary> private void SetBtnStyle(Button btn) ...

  8. 安卓开发之viewpager学习(头条显示)

    activity_luancher.xml代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res ...

  9. 输出内容(document.write)

    document.write() 直接在页面中输出内容 第一种 直接输出 document.write("I Love Javascript !") //输出内容为:I Love ...

  10. java浮点数剖析

    定点数表达法的缺点在于其形式过于僵硬,固定的小数点位置决定了固定位数的整数部分和小数部分,不利于同时表达特别大的数或者特别小的数.计算机系统采纳了所谓的浮点数表达方式.这种表达方式利用科学计数法来表达 ...