Naive and Silly Muggles

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

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
 
Source
 


题目大意:
给你三个点,找一个最小的圆能把三个点包住。点可以允许在圆内。再给你另一个点,如果该点在圆内或圆上输出Danger,在圆外输出Safe。开始写的是直接算外接圆,这样三个点都在圆上,第三组数据过不了。看了下博博的代码,没想到直接算重心?正在想为什么的时候,就听到吉吉说是数据水了。。我们求外接圆的话对锐角三角形是可以的,但是如果是钝角三角形的话。可以把圆适当的往钝角所对的边中点移动,那样半径会变小。因为题目说了点可以在圆内或者圆上。



如图,如果是锐角三角形,外心肯定在三角形内。如左图中P的位置,如果往四方移动,半径肯定会扩大,所以这种情况可以直接解方程组。如果是钝角三角形,如右图,外心在P处,BC的中垂线上到BC两点距离相等,PQ之间都可以把A包进去。要找一个半径最小的圆。当然是以 Q为圆心QB为半径的圆啦。具体实现见代码。

题目地址:Naive and Silly Muggles

 AC代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdio>
using namespace std; int main()
{
int tes;
int cas=0;
double x1,y1,x2,y2,x3,y3,a,b,r2,x,y;
scanf("%d",&tes);
while(tes--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y);
//先求出这三个点的外接圆(x-a)^2+(y-b)^2=r^2;
//r2代表r的平方 //先判断锐角钝角三角形 if((x2-x1)*(x3-x1)+(y2-y1)*(y3-y1)<0) //(x1,y1)为钝角
{
a=(x3+x2)/2.0,b=(y3+y2)/2.0;
r2=(a-x2)*(a-x2)+(b-y2)*(b-y2);
}
else if((x1-x2)*(x3-x2)+(y1-y2)*(y3-y2)<0) //(x2,y2)为钝角
{
a=(x3+x1)/2.0,b=(y3+y1)/2.0;
r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
}
else if((x1-x3)*(x2-x3)+(y1-y3)*(y2-y3)<0) //(x3,y3)为钝角
{
a=(x2+x1)/2.0,b=(y2+y1)/2.0;
r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
}
else
{
a=((x1*x1+y1*y1-x2*x2-y2*y2)*(y1-y3)-(x1*x1+y1*y1-x3*x3-y3*y3)*(y1-y2))/(2.0*((y1-y3)*(x1-x2)-(y1-y2)*(x1-x3)));
b=((x1*x1+y1*y1-x2*x2-y2*y2)*(x1-x3)-(x1*x1+y1*y1-x3*x3-y3*y3)*(x1-x2))/(2.0*((x1-x3)*(y1-y2)-(x1-x2)*(y1-y3)));
r2=(x1-a)*(x1-a)+(y1-b)*(y1-b);
}
if((x-a)*(x-a)+(y-b)*(y-b)<=r2)
printf("Case #%d: Danger\n",++cas);
else
printf("Case #%d: Safe\n",++cas);
}
return 0;
}


HDU 4720Naive and Silly Muggles热身赛2 1005题(分锐角钝角三角形讨论)的更多相关文章

  1. HDU 4690 EBCDIC (2013多校 1005题 胡搞题)

    EBCDIC Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Su ...

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

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

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

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

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

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

  5. Naive and Silly Muggles

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

  6. Naive and Silly Muggles (计算几何)

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

  7. Naive and Silly Muggles hdu4720

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

  8. HDUOJ-------Naive and Silly Muggles

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

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

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

随机推荐

  1. IOS数据本地存储的四种方式--

    注:借鉴于:http://blog.csdn.net/jianjianyuer/article/details/8556024 在IOS开发过程中,不管是做什么应用,都会碰到数据保存问题.将数据保存到 ...

  2. JavaScript基础知识----基本语法

    JavaScript 语句 JavaScript 语句向浏览器发出的命令.语句的作用是告诉浏览器该做什么. 分号 ; 分号用于分隔 JavaScript 语句. 通常我们在每条可执行的语句结尾添加分号 ...

  3. 高级UNIX环境编程7 进程

    每个程序都会收到一张环境表 extern char **environ; c程序的存储空间布局: 正文段:共享,只读 初始化数据段:存函数以外的赋值 非初始化数据段(bbs):block starte ...

  4. Hadoop Hive sql语法详解

    Hadoop Hive sql语法详解 Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构 化的数据文件 ...

  5. cocos2d-x游戏开发系列教程-超级玛丽03-main函数

    代码下载链接 http://download.csdn.net/detail/yincheng01/6864893 解压密码:c.itcast.cn main函数内容 #include "m ...

  6. 【转】 /etc/fstab功能详解

    [转] /etc/fstab功能详解 最近去客户现场时,遇到 了一个关于挂载文件/etc/fstab文件的问题,就写了一下/etc/fstab文件的作用一个文件中各个参数的含义.供大家参考有不正确的地 ...

  7. iOS 之 UINavigationController 记录

    有一阵子没有写随笔,感觉有点儿手生.一个多月以后终于又一次坐下来静下心写随笔,记录自己的学习笔记,也希望能够帮到大家. 废话少说回到正题,UINavigationController是IOS编程中比较 ...

  8. Hibernate 多对一

    Hibernate的many-to-one 关联. 具体看配置文件: <?xml version="1.0"?> <!DOCTYPE hibernate-mapp ...

  9. POJ 1861 Network (模版kruskal算法)

    Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: Accepted: Special Judge Descripti ...

  10. Chapter 10 模版方法模式

    我们要完成在某一细节层次一致的一个过程或一系列步骤,但其个别步骤在更详细的层次上的实现可能不同时,我们通常考虑用模版模式来处理. 模版方法模式:定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模 ...