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

题目大意就是先求一个能包含三个点的最小圆,然后判断第四个圆是否在圆内。

这三点中取出两点,如果以这两个点构成的线段为直径,能包含第三个点,自然便是最小圆。于是先考虑最远的两个点即可。

其次,如果上述不满足(三点一线的满足上面),自然需要逐步扩大直径来包含第三个点,自然所求的便是外接圆。

对于求外接圆,此处采用了暴力设圆心坐标(x, y)

所以(x-x1)^2 + (y-y1)^2 = (x-x2)^2 + (y-y2)^2 = (x-x3)^2 + (y-y3)^2

化简得到:

2*((x1-x2)*(y1-y3) - (x1-x3)*(y1-y2)) * x

= (y1-y2)*(y2-y3)*(y1-y3) + (x1*x1-x2*x2)*(y1-y3) - (x1*x1-x3*x3)*(y1-y2);

2*((y1-y2)*(x1-x3) - (y1-y3)*(x1-x2)) * y

= (x1-x2)*(x2-x3)*(x1-x3) + (y1*y1-y2*y2)*(x1-x3) - (y1*y1-y3*y3)*(x1-x2);

于是圆心求出来问题便简单了。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#define LL long long using namespace std; double x1,x2,x3,y1,y2,y3, x0, y0;
double rx, ry, r2;
int n,i; void Cal()
{
double A, B;
A = *((x1-x2)*(y1-y3) - (x1-x3)*(y1-y2));
B = (y1-y2)*(y2-y3)*(y1-y3) + (x1*x1-x2*x2)*(y1-y3) - (x1*x1-x3*x3)*(y1-y2);
rx = B/A; A = *((y1-y2)*(x1-x3) - (y1-y3)*(x1-x2));
B = (x1-x2)*(x2-x3)*(x1-x3) + (y1*y1-y2*y2)*(x1-x3) - (y1*y1-y3*y3)*(x1-x2);
ry = B/A;
r2 = (rx-x1)*(rx-x1) + (ry-y1)*(ry-y1);
} void Work()
{
int cnt = ;
double tmp;
r2 = ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))/;
rx = (x1+x2)/;
ry = (y1+y2)/;
tmp = ((x2-x3)*(x2-x3) + (y2-y3)*(y2-y3))/;
if (tmp > r2)
{
cnt = ;
r2 = tmp;
rx = (x3+x2)/;
ry = (y3+y2)/;
}
tmp = ((x1-x3)*(x1-x3) + (y1-y3)*(y1-y3))/;
if (tmp > r2)
{
cnt = ;
r2 = tmp;
rx = (x1+x3)/;
ry = (y1+y3)/;
}
switch (cnt)
{
case :
tmp = (rx-x1)*(rx-x1) + (ry-y1)*(ry-y1);
break;
case :
tmp = (rx-x2)*(rx-x2) + (ry-y2)*(ry-y2);
break;
case :
tmp = (rx-x3)*(rx-x3) + (ry-y3)*(ry-y3);
break;
}
if (tmp > r2)
{
Cal();
}
} void Output()
{
if (r2 >= (rx-x0)*(rx-x0) + (ry-y0)*(ry-y0))
printf("Danger\n");
else
printf("Safe\n");
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for(int times = ; times <= T; times++)
{
scanf("%lf%lf", &x1, &y1);
scanf("%lf%lf", &x2, &y2);
scanf("%lf%lf", &x3, &y3);
scanf("%lf%lf", &x0, &y0);
Work();
printf("Case #%d: ", times);
Output();
}
}

ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)的更多相关文章

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

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

  2. ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)

    Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...

  3. ACM学习历程—HDU1392 Surround the Trees(计算几何)

    Description There are a lot of trees in an area. A peasant wants to buy a rope to surround all these ...

  4. Naive and Silly Muggles hdu4720

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

  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. HDU 4720 Naive and Silly Muggles (简单计算几何)

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

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

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

  8. Naive and Silly Muggles

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

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

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

随机推荐

  1. Nginx https免费SSL证书配置指南

    生成证书 $ cd /usr/local/nginx/conf $ openssl genrsa -des3 -out server.key 1024 $ openssl req -new -key  ...

  2. MVC项目总结

    View命名 View下有多个模块的文件夹,我们根据微软的规定,每个模块下的首页都为Index.cshtml命名 获得当前页面的控制器名称 var currentControllerName = th ...

  3. Qt QImageReader 相似乎有bug

    Qt 版本号 5.4.1 (VS2010) 近期在做一个小程序,事实上非常easy,就是打开一个gif 动画.能够静态显示当中随意一帧图像.Qt 中有一个QImageReader 类.用这个类理论上说 ...

  4. C#如何遍历数组?

    // 一维数组 int[] arr = { 1, 2, 3, 4, 5 }; foreach (int i in arr) { Console.WriteLine(i.ToString() + &qu ...

  5. TP 接收post请求使用框架自带函数I()防止注入

    <input id="dele_id[]" value="1" type="checkbox" /> <input id= ...

  6. ES通过API调整设置

    1.查询es的设置信息 2.查询单个索引的设置 3.设置复制集为0

  7. 九度OJ 1064:反序数 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3758 解决:2773 题目描述: 设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321) 求N的值 输入: 程序无任 ...

  8. python中的特殊用法

    1 别名 from xxx import xxx as xxx;

  9. 前端mvc组合框架

    1. jquery 2. underscore 3. backbone 4. reactjs 5. seajs

  10. Ubuntu下如何配置使终端透明

    今天学习了一招如何将Ubuntu下的终端背景颜色变得透明,感觉透明之后有好处,比如网上有些命令,可以直接覆盖原来的网页察看,然后敲击命令. 下面就来看看终端背景变透明前后的对比效果. 完全不透明,最大 ...