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/ ...
随机推荐
- Attribute "resultType" must be declared for element type "insert".
这是mybatis插入数据库之后出现的问题,至于为什么出现这个问题,是因为插入的时候你照抄了查询的语句,插入的时候只有id属性和parameterType属性,并没有“resultType”属性,要注 ...
- mybatis的两种分页方式:RowBounds和PageHelper
原理:拦截器. 使用方法: RowBounds:在mapper.java中的方法中传入RowBounds对象. RowBounds rowBounds = new RowBounds(offset, ...
- 畅通project再续 HDU杭电1875 【Kruscal算法 || Prim】
Problem Description 相信大家都听说一个"百岛湖"的地方吧.百岛湖的居民生活在不同的小岛中.当他们想去其它的小岛时都要通过划小船来实现.如今政府决定大力发展百岛湖 ...
- 深入Asyncio(十一)优雅地开始与结束
Startup and Shutdown Graceful 大部分基于asyncio的程序都是需要长期运行.基于网络的应用,处理这种应用的正确开启与关闭存在惊人的复杂性. 开启相对来说更简单点,常规做 ...
- 深入浅出Stream和parallelStream
https://blog.csdn.net/darrensty/article/details/79283146
- 两个DataGridEHToExcel
procedure TForm1.N1Click(Sender: TObject); var GridtoExcel: TDBGridEhToExcel; begin try Gri ...
- libEasyPlayer RTSP windows播放器SDK API接口设计说明
概述 libEasyPlayer实现对RTSP直播流进行实时采集和解码显示,稳定,高效,低延时:解码可采用intel硬件解码和软件解码两种方式,能实时进行录像和快照抓图,OSD叠加等功能. API接口 ...
- 替代或者与 Redis 配合存储十亿级别列表的数据.
http://ssdb.io/docs/zh_cn/index.html 用户案例 如果你在生产环境中使用 SSDB, 欢迎你给我发邮件(ssdb#udpwork.com), 我很愿意把你加入到下面的 ...
- Neural Task Programming: Learning to Generalize Across Hierarchical Tasks
Neural Task Programming: Learning to Generalize Across Hierarchical Tasks
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.
今天电脑死机了2次,重启电脑开eclipse后,发现项目环境坏了.百度后得到的答案是删除.metadata目录.但觉得麻烦,后在stackoverflow发现最佳的方式是 把 .metadata/.p ...