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/ ...
随机推荐
- 时钟展频技术能有效降低EMI,深入讲解展频发生器!
原文地址:https://baijiahao.baidu.com/s?id=1608649367453023659&wfr=spider&for=pc 相关文章: 1.http://b ...
- Pentaho Work with Big Data(五)—— 格式化原始web日志
本演示样例说明怎样使用Pentaho MapReduce把原始web日志解析成格式化的记录. 一.向HDFS导入演示样例数据文件 将weblogs_rebuild.txt文件放到HDFS的/user/ ...
- 宜人贷PaaS数据服务平台Genie:技术架构及功能
上篇:架构及组件 一.数据平台的发展 1.1 背景介绍 随着数据时代的到来,数据量和数据复杂度的增加推动了数据工程领域的快速发展.为了满足各类数据获取/计算等需求,业内涌现出了诸多解决方案.但大部分方 ...
- eclipse-jee版配置tomcat
Eclipse作为一款优秀的java开发开源IDE,集成了许多优秀的开发控件.下来我就如何安装eclipse及插件进行说明: 一.JDK安装 JDK是作为整个java的核心,包括运行环境,编译工具 ...
- K均值算法总结
这几天在一个项目上需要用到K均值聚类算法,以前都是直接利用百度老师copy一个Kmeans算法代码,这次想自己利用已知的算法思想编写一下,编写才知道,虽然熟悉了算法思想,真正实现时,还是遇到不少bug ...
- Frege-基于JVM的类Haskell纯函数式编程语言
Frege是一门受Haskell语言启示而设计的纯函数式编程语言.Frege程序会被编译为Java,并执行于JVM上.它与Haskell是如此的类似.以至于有人称它为JVM上的Haskell.取Fre ...
- C#连接Oracle的问题(不安装客户端)
win7环境,本地没有安装oracle或者客户端,现在需要程序里连接远程oracle DB: 如果采用System.Data.OracleClient肯定是不行的,这个要安装客户端的: 所以就尝试O ...
- go module
前言 go 1.5 引进了vendor管理工程依赖包,但是vendor的存放路径是在GOPATH底下,另外每个依赖还可以有自己的vendor,通常会弄得很乱,尽管dep管理工具可以将vendor平级化 ...
- EasyNVR NVR网页无插件直播在兼容宇视NVR RTSP流媒体时PLAY过程对Scale的兼容
前一段在维护EasyNVR客户的过程中遇到一个问题,在接入宇视NVR的时候,就是明明在vlc中能非常正常播放的视频流,却用EasyRTSPClient RTSP客户端拉流的协议交互过程中,PLAY命令 ...
- ubuntu 安装 pygame 很好玩的东西
1. 简介 pygame 是基于对 SDL库的python 封装,提供python接口.SDL(Simple DirectMedia Layer) 是一个跨平台的游戏开发库,方便游戏开发和移植.目前最 ...