HDU 4720Naive and Silly Muggles热身赛2 1005题(分锐角钝角三角形讨论)
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
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?
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.
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
Case #2: Safe
Case #3: Safe
题目大意:
给你三个点,找一个最小的圆能把三个点包住。点可以允许在圆内。再给你另一个点,如果该点在圆内或圆上输出Danger,在圆外输出Safe。开始写的是直接算外接圆,这样三个点都在圆上,第三组数据过不了。看了下博博的代码,没想到直接算重心?正在想为什么的时候,就听到吉吉说是数据水了。。我们求外接圆的话对锐角三角形是可以的,但是如果是钝角三角形的话。可以把圆适当的往钝角所对的边中点移动,那样半径会变小。因为题目说了点可以在圆内或者圆上。
#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题(分锐角钝角三角形讨论)的更多相关文章
- HDU 4690 EBCDIC (2013多校 1005题 胡搞题)
EBCDIC Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Su ...
- HDU 4720 Naive and Silly Muggles (简单计算几何)
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 ...
- 计算几何 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/ ...
- Naive and Silly Muggles hdu4720
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDUOJ-------Naive and Silly Muggles
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)
Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...
随机推荐
- r语言之生成规则序列,规则序列函数及用法
在生成序列时,“:”的优先级最高 (1)从1到20的整数序列: > 1:20 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 (2) ...
- 数组排序-Objectivec
发表于昨天(23:33)(2013-11-03 23:33) ,已有15次阅读 ,共0个评论 摘要: 总结OC中数组排序3种方法:sortedArrayUsingSelector:;sortedArr ...
- 【转】论文、会议、期刊评价|Indicate paper, conference, Journal
转自“浙江大学计算机学院软硬件协同设计实验室”:http://multicore.zju.edu.cn/fatlab/Indicate-paper.htm 1 体系结构领域,排名为 ...
- git 删除右键菜单
cmd进入"C:\Program Files (x86)\Git\git-cheetah"目录,运行regsvr32 /u git_shell_ext(64).dll
- referer htttp headers 统计信息 防盗链
HTTP headers是HTTP请求和相应的核心模块,它承载了关于客户端浏览器.请求页面.服务器等相关信息.Referer是HTTP头中的一个属性,告诉服务器我是从哪个页面链接过来的,所携带的信息用 ...
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 S ...
- route-over VS mesh-under
近期在网上看到一篇专门介绍route-over和Mesh-under的论文,介绍的比較具体: ip=183.63.119.35&id=1582643&acc=ACTIVE%20SERV ...
- NAT简单介绍
NAT本质就是让一群机器公用同一个IP.还有一个重要的用途是保护NAT内的主机不受外界攻击 NAT类型: 1.Full Cone:IPport不受限 Full Cone仅仅做单纯的地址转换,不正确进出 ...
- eclipse config 3 构造pydev
什么是不是说生命是短暂的.我用python 准备工作 sudo apt-get install python3-dev 例如以下操作 依次点击菜单 Help->Install New Softw ...
- SDRAM 控制器的解析
本篇博文非原创,是整理了网上的各家之言与一体,为自己以后方便查询所用.如有冒犯请告之. 1.Precharge与Refresh的区别? plj:两者都是对存储单元的电容进行充电.回写.但差异在于: P ...