Naive and Silly Muggles
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 xi and yi (|xi, yi| <= 10), indicating the three wizards' positions. Then a single line with two numbers qx and qy (|qx, qy| <= 10), indicating the muggle's position.
3
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
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const double eps = 1e-; int sgn(double x)
{
if(fabs(x) < eps) return ;
if ( x < ) return -;
else return ;
}
struct Point
{
double x,y;
Point(double _x = , double _y = )
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
};
double dist(Point a,Point b)
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
//过三点求圆心坐标
Point waixin(Point a,Point b,Point c)
{
double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/;
double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/;
double d = a1*b2 - a2*b1;
return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 -a2*c1)/d);
}
//圆心要么是三条线段的中点,或外心
int main()
{
int T;
int cnt = ;
Point p[];
scanf("%d",&T);
while(T--)
{
for(int i = ; i < ; i++) p[i].input();
Point res;
double tmp = 1e20;
for(int i = ; i < ; i++) //求出三条线段一半最长值
{
Point t = Point((p[i].x+p[(i+)%].x)/,(p[i].y+p[(i+)%].y)/);
double dd = max(dist(p[],t),max(dist(p[],t),dist(p[],t)));
if(dd < tmp)
{
tmp = dd;
res = t;
}
}
if(sgn( (p[]-p[])^(p[]-p[]) ) != )
{
Point t = waixin(p[],p[],p[]);
double dd = max(dist(p[],t),max(dist(p[],t),dist(p[],t)));
if(dd < tmp) tmp = dd;
}
printf("Case #%d: ",++cnt);
if(sgn(tmp - dist(res,p[])) >= ) printf("Danger\n");
else printf("Safe\n");
}
return ;
}
计算机几何(圆的外心)
Naive and Silly Muggles的更多相关文章
- 计算几何 HDOJ 4720 Naive and Silly Muggles
题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/a ...
- 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 ...
- 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/ ...
- ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)
Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...
- HDU-4720 Naive and Silly Muggles 圆的外心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 先两两点之间枚举,如果不能找的最小的圆,那么求外心即可.. //STATUS:C++_AC_0M ...
- HDU 4720 Naive and Silly Muggles 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 题目大意:给你四个点,用前三个点绘制一个最小的圆,而这三个点必须在圆上或者在圆内,判断最一个点如 ...
- HDU 4720 Naive and Silly Muggles 平面几何
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...
随机推荐
- java 面向对象——进度1
面向对象:1,面向对象和面向过程思想. 面向对象强调的是对象实例. 面向过程强调的是动作. 对象将动作进行封装. 在问题领域中,我们先去找的都是涉及的对象, 然后 ...
- js中使用prototype扩展对象方法
//---------------------对象 //1. var HomeContrl = function(){ this.foo = 'bar'; //对象方法 this.intro = fu ...
- laravel队列-让守护进程处理耗时任务
待解决的问题 最近在做一个服务器集群管理的web项目,需要处理一些极其耗时的操作,比如磁盘格式化分区.对于这个需求,最开始的想法是,为了让节点上的rpc(远程过程调用) service端尽可能简单(简 ...
- 阿里云服务器CentOS 5.7(64位)安装配置LAMP服务器(Apache+PHP5+MySQL)
一.快速安装Apache+PHP5+MySql ----------------------------------------------------- 补充:由于163的yum源上只有php5.1 ...
- Linux Makefile analysis for plain usr
一.本文主旨 笔者写了一篇linux内核Makefile整体分析 ,测重于理论分析,对于实际应用不算对头,所以需要写一篇实用性较强的文章,为以后内核.驱动移植做好铺垫. 二.本文内容概要 1.编译哪些 ...
- SpringMVC Maven创建项目
一.配置Maven环境: 1.去官网下载好Maven,并解压: 2.添加环境变量: ①添加环境变量,如下: ②把maven的bin目录添加到环境变量path下面,如下(我系统是win10,win7编辑 ...
- nginx提示No input file specified怎么办
用了网上提供的各种方法都不行,即便html能正常打开,php文件依然有问题.而后继续尝试了修改权限 chown -vR www:www /folder 功能都正常. nginx.conf 的 user ...
- Android之单复选框及Spinner实现二级联动
一.基础学习 1.图形学真的很神奇啊....查了些资料做出了3D云标签,哈哈...其实直接拿来用的,我们要效仿鲁迅先生的拿来主义,嘿嘿~~3D标签云就是做一个球面,然后再球面上取均匀分布的点,把点坐标 ...
- uva 11922 - Permutation Transformer
splay的题: 学习白书上和网上的代码敲的: #include <cstdio> #include <cstring> #include <cstdlib> #i ...
- how to develop mobile web
http://blog.templatemonster.com/2010/05/11/how-make-mobile-website-6-easy-tips/ http://mobile.smashi ...