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/ ...
随机推荐
- Django之信息聚合
feeds.py #coding:utf-8 __author__ = 'similarface' from django.contrib.syndication.views import Feed ...
- 搜狐新闻APP是如何使用HUAWEI DevEco IDE快速集成HUAWEI HiAI Engine
6月12日,搜狐新闻APP最新版本在华为应用市场正式上线啦! 那么,这一版本的搜狐新闻APP有什么亮点呢? 先抛个图,来直接感受下—— 模糊图片,瞬间清晰! 效果杠杠的吧. 而藏在这项神操作背后的 ...
- 检查Nginx的配置,重载配置和重启的方法
Nginx 安装后只有一个程序文件,本身并不提供各种管理程序,它是使用参数和系统信号机制对 Nginx 进程本身进行控制的. Nginx 的参数包括有如下几个: 可以这样使用 /usr/local/n ...
- 1930: [Shoi2003]pacman 吃豆豆
1930: [Shoi2003]pacman 吃豆豆 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1969 Solved: 461[Submit][ ...
- 九度OJ 1008:最短路径问题 (最短路)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8064 解决:2685 题目描述: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费 ...
- CentOS、乌班图设置固定静态IP
CentOS.乌班图设置固定静态IP 一.centOS 1.编辑 ifcfg-eth0 文件 # vim /etc/sysconfig/network-scripts/ifcfg-eth0 2,在文件 ...
- 2017-2018-1 20179209《Linux内核原理与分析》第五周作业
一.实验:使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用 环境说明 实验环境为 Ubuntu16.10 和 实验楼环境. 选择39号系统调用实验.39号系统调用为mkdir系统调用. ...
- 使用python实现二分法查找
最近开始学习mit的python课程,其中手工实现的一个关于二分法查找的练习代码个人感觉比较有参考价值,贴上来分享交流一下. 主要功能是在1-100中自己猜测一个数值,随后系统产生数值看是否符合猜测, ...
- 流畅python学习笔记:第十四章:迭代器和生成器
迭代器和生成器是python中的重要特性,本章作者花了很大的篇幅来介绍迭代器和生成器的用法. 首先来看一个单词序列的例子: import re re_word=re.compile(r'\w+') c ...
- Wireshark学习笔记——怎样高速抓取HTTP数据包
0.前言 在火狐浏览器和谷歌浏览器中能够很方便的调试network(抓取HTTP数据包),可是在360系列浏览器(兼容模式或IE标准模式)中抓取HTTP数据包就不那么那么方便了.尽管也可使用H ...