HDU 4720 Naive and Silly Muggles (简单计算几何)
Naive and Silly Muggles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 24 Accepted Submission(s): 17
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.
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
首先是找出一个最小的圆来覆盖三个点。
圆心要么是三条线段的中点,或者三角形的外心,很容易找出来。‘
然后判断点是否在圆外就可以了
/* ***********************************************
Author :kuangbin
Created Time :2013-9-11 13:17:28
File Name :2013-9-11\1005.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
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()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int iCase = ;
Point p[];
scanf("%d",&T);
while(T--)
{
iCase++;
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;
res = t;
} }
printf("Case #%d: ",iCase);
if(sgn(tmp - dist(res,p[])) >= )
printf("Danger\n");
else printf("Safe\n");
}
return ;
}
HDU 4720 Naive and Silly Muggles (简单计算几何)的更多相关文章
- 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 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 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...
- 计算几何 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/ ...
- ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)
Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...
- Naive and Silly Muggles
Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...
- 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 圆的外心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 先两两点之间枚举,如果不能找的最小的圆,那么求外心即可.. //STATUS:C++_AC_0M ...
随机推荐
- java基础46 IO流技术(输出字符流/缓冲输出字符流)
一.输出字符流 1.1.输出字符流体系 --------| Writer:输出字符流的基类(抽象类) ----------| FileWriter:向文件输出数据输出字符流(把程序中的数据写到硬盘中 ...
- Java线程:新特征-有返回值的线程《转》
原始文章 在Java5之前,线程是没有返回值的,常常为了“有”返回值,破费周折,而且代码很不好写.或者干脆绕过这道坎,走别的路了. 现在Java终于有可返回值的任务(也可以叫做线程)了. ...
- Unix IPC之Posix消息队列(1)
部分参考:http://www.cnblogs.com/Anker/archive/2013/01/04/2843832.html IPC对象的持续性:http://book.51cto.com/ar ...
- centos 6.x 部署uwsgi+flask项目
一.项目背景 1. 公司需求要做一个在线统计页面; 2. 统计在线人数,进行人数数据展示; 3. 类似QQ官网在线人数 二.测试环境 [root@linux-node2 ~]# cat /etc/*r ...
- sqlserver字符串合并(merge)方法汇总
--方法1--使用游标法进行字符串合并处理的示例.--处理的数据CREATE TABLE tb(col1 varchar(10),col2 int)INSERT tb SELECT 'a',1UNIO ...
- CVE-2013-0025
Microsoft IE ‘SLayoutRun’释放后重用漏洞(CNNVD-201302-197) Microsoft Internet Explorer是微软Windows操作系统中默认捆绑的WE ...
- nginx-request_time和upstream_response_time
1.request_time 官网描述:request processing time in seconds with a milliseconds resolution; time elapsed ...
- HBase(三)HBase架构与工作原理
一.系统架构 注意:应该是每一个 RegionServer 就只有一个 HLog,而不是一个 Region 有一个 HLog. 从HBase的架构图上可以看出,HBase中的组件包括Client.Zo ...
- mac系统编译安装ImageMagick7.0.1-3
1.下载源码包: git clone http://git.imagemagick.org/repos/ImageMagick.git 2.编译安装: cd ImageMagick/ ./config ...
- PLSQL Developer个性化设置
1)代码自动完成 和讨厌的.才后出现提示说88,我用快捷键任意呼唤. Tools->Preferences->User Interface->Key Configuration.找到 ...