ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)
Description
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
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
Sample Input
Sample Output
题目大意就是先求一个能包含三个点的最小圆,然后判断第四个圆是否在圆内。
这三点中取出两点,如果以这两个点构成的线段为直径,能包含第三个点,自然便是最小圆。于是先考虑最远的两个点即可。
其次,如果上述不满足(三点一线的满足上面),自然需要逐步扩大直径来包含第三个点,自然所求的便是外接圆。
对于求外接圆,此处采用了暴力设圆心坐标(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(计算几何)的更多相关文章
- HDU-4720 Naive and Silly Muggles 圆的外心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 先两两点之间枚举,如果不能找的最小的圆,那么求外心即可.. //STATUS:C++_AC_0M ...
- ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)
Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...
- 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 ...
- Naive and Silly Muggles hdu4720
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 4720 Naive and Silly Muggles (外切圆心)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 4720 Naive and Silly Muggles (简单计算几何)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 计算几何 HDOJ 4720 Naive and Silly Muggles
题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/a ...
- Naive and Silly Muggles
Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...
- Naive and Silly Muggles (计算几何)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- PHP RSA加解密示例(转)
1.生成密钥和公钥 开始前需要准备openssl环境 linux 需要安装openssl工具包,传送门http://www.openssl.org/source/ window 下需要安装openss ...
- dede二级导航与二级栏目 ----内容介绍二级导航
{dede:channelartlist typeid='top'}//如果只需要拿一列,则需要使用row='1'这个属性否则会根据子频道的数目循环输出 <a href="{dede: ...
- C与C++在形參的一点小差别
先看一下以下的代码: int fun(a,b) int a; int b; { return 10; } void main(int argc, char ** argv) { fun(10); re ...
- 底部TabsFooter
Demo简单描述:点击底部菜单可切换页面,并且底部为共用. 这个是在设置好导航Navigator之后进行的步骤,只是我个人进行Tab切换的一种思路方法,或许不是最好的,仅供参考一下. 首先我们需要一个 ...
- PHP部分--图片上传服务器、图片路径存入数据库,并读取
html页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- 关于-O0、O1、O2、O3优化
少优化->多优化: O0 -->> O1 -->> O2 -->> O3 -O0表示没有优化,-O1为缺省值,-O3优化级别最高 整理自网络,仅供参考 1.- ...
- 【BZOJ2427】[HAOI2010]软件安装 Tarjan+树形背包
[BZOJ2427][HAOI2010]软件安装 Description 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为 ...
- Complete space 完备空间与柯西序列 巴拿赫空间与完备空间 完备空间与和希尔伯特空间 封闭closed与完备性complete
http://www.gatsby.ucl.ac.uk/~gretton/coursefiles/RKHS2013_slides1.pdf RKHS: a function space with a ...
- 【CISCO强烈推荐】生成树 《路由协议》 卷一二 拥塞:网络延迟 阻塞:进程中 MTU QS:服务质量 OSPF RIP ISIS BGP 生成树 《路由协议》 卷一二
协议 CP/IP路由技术第一卷 作 者 (美)多伊尔,(美)卡罗尔
- thinkphp5 (最棒的php开源框架)
tp5的唯一可访问目录是public,即项目根目录: http://localhost/tp5/public/ 开发规范: 类库.函数文件统一以.php为后缀 类(命名和路径)和命名空间保持一致 类文 ...