Naive and Silly Muggles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 61    Accepted Submission(s): 39

Problem Description
Three wizards are doing a experiment. To avoid from bothering, a special magic is set around them. The magic forms a circle, which covers those three wizards, in other words, all of them are inside or on the border of the circle. And due to save the magic power, circle's area should as smaller as it could be. 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
The first line has a number T (T <= 10) , indicating the number of test cases. 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.
 
Output
For test case X, output "Case #X: " first, then output "Danger" or "Safe".
 
Sample Input
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
几何题:
考虑的事情有:
       (1)三点是否在一条直线上...求出前后坐标,得出圆心,和半径r;
       (2)区分锐角和钝角三角形....锐角三角形(最小的圆为其外接圆),钝角三角形以最长边为直径做圆为其最小圆面积...
 于是 有一点必须要注意,那就是求 外接圆的中心坐标(x,y)
代码wei:
 通俗算法
定义:设平面上的三点A(x1,y1),B(x2,y2),C(x3,y3),定义
S(A,B,C) = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) 已知三角形的三个顶点为A(x1,y1),B(x2,y2),C(x3,y3),则该三角形的外心为:
S((x1*x1+y1*y1, y1), (x2*x2+y2*y2, y2), (x3*x3+y3*y3, y3))
x0 = -----------------------------------------------------------
*S(A,B,C) S((x1,x1*x1+y1*y1), (x2, x2*x2+y2*y2), (x3, x3*x3+y3*y3))
y0 = -----------------------------------------------------------
*S(A,B,C)

代码形式:

 //求外接圆的圆心
double S(double x1,double y1,double x2,double y2,double x3,double y3){
return ((x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) );
} double getx(double x1,double y1,double x2,double y2,double x3,double y3){
return (S(x1*x1+y1*y1,y1, x2*x2+y2*y2, y2,x3*x3+y3*y3,y3)/(*S(x1,y1,x2,y2,x3,y3)) );
} double gety(double x1,double y1,double x2,double y2,double x3,double y3){
return (S(x1, x1*x1+y1*y1, x2, x2*x2+y2*y2, x3, x3*x3+y3*y3) / (*S(x1,y1,x2,y2,x3,y3)));
}
Sample Output
Case #1: Danger
Case #2: Safe
Case #3: Safe
 此题代码为:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
bool isline(double *a,double *b,double *c)
{
if(fabs((b[]-a[])*(c[]-a[])-(c[]-a[])*(b[]-a[]))<1e-)
return ;
else
return ;
}
//求外接圆的圆心
double S(double x1,double y1,double x2,double y2,double x3,double y3){
return ((x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) );
} double getx(double x1,double y1,double x2,double y2,double x3,double y3){
return (S(x1*x1+y1*y1,y1, x2*x2+y2*y2, y2,x3*x3+y3*y3,y3)/(*S(x1,y1,x2,y2,x3,y3)) );
} double gety(double x1,double y1,double x2,double y2,double x3,double y3){
return (S(x1, x1*x1+y1*y1, x2, x2*x2+y2*y2, x3, x3*x3+y3*y3) / (*S(x1,y1,x2,y2,x3,y3)));
}
//求两条边的夹角
bool iftrue(double *a,double *b,double *c )
{
return (a[]-b[])*(c[]-b[])+(a[]-b[])*(c[]-b[])>?:; //不是锐角时yes
}
//求两点间的距离
double distan(double *a,double *b)
{
return sqrt((a[]-b[])*(a[]-b[])+(a[]-b[])*(a[]-b[]))/2.0;
} int main()
{
int t,count,i;
double po[][],r,save[][],x,y;
scanf("%d",&t);
for(count=;count<=t;count++)
{
for(i=;i<;i++)
{
scanf("%lf%lf",&po[i][],&po[i][]);
if(i==||save[][]*save[][]+save[][]*save[][]<po[i][]*po[i][]+po[i][]*po[i][])
save[][]=po[i][],save[][]=po[i][];
if(i==||save[][]*save[][]+save[][]*save[][]>po[i][]*po[i][]+po[i][]*po[i][])
save[][]=po[i][],save[][]=po[i][];
}
if(isline(po[],po[],po[]))
{
r=sqrt((save[][]-save[][])*(save[][]-save[][])+(save[][]-save[][])*(save[][]-save[][]))/2.0;
x=(save[][]+save[][])/2.0;
y=(save[][]+save[][])/2.0;
}
else
{
bool judge[];
judge[]=iftrue(po[],po[],po[]);
judge[]=iftrue(po[],po[],po[]);
judge[]=iftrue(po[],po[],po[]);
if(judge[]||judge[]||judge[])
{
if(judge[])
{
x=(po[][]+po[][])/2.0;
y=(po[][]+po[][])/2.0;
r=distan(po[],po[]);
}
else if(judge[])
{
x=(po[][]+po[][])/2.0;
y=(po[][]+po[][])/2.0;
r=distan(po[],po[]);
}
else if(judge[])
{
x=(po[][]+po[][])/2.0;
y=(po[][]+po[][])/2.0;
r=distan(po[],po[]);
}
}
else
{
//当为锐角时,求其外接圆,否者不求
x=getx(po[][],po[][],po[][],po[][],po[][],po[][]);
y=gety(po[][],po[][],po[][],po[][],po[][],po[][]);
r=sqrt((po[][]-x)*(po[][]-x)+(po[][]-y)*(po[][]-y));
}
}
double temp=sqrt((po[][]-x)*(po[][]-x)+(po[][]-y)*(po[][]-y));
if(r>temp-1e-)
printf("Case #%d: Danger\n",count);
else
printf("Case #%d: Safe\n",count);
}
return ;
}

HDUOJ-------Naive and Silly Muggles的更多相关文章

  1. 计算几何 HDOJ 4720 Naive and Silly Muggles

    题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/a ...

  2. Naive and Silly Muggles

    Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...

  3. Naive and Silly Muggles (计算几何)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  4. HDU 4720 Naive and Silly Muggles (外切圆心)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  5. Naive and Silly Muggles hdu4720

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  6. HDU 4720 Naive and Silly Muggles (简单计算几何)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  7. ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)

    Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...

  8. HDU-4720 Naive and Silly Muggles 圆的外心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 先两两点之间枚举,如果不能找的最小的圆,那么求外心即可.. //STATUS:C++_AC_0M ...

  9. HDU 4720 Naive and Silly Muggles 2013年四川省赛题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 题目大意:给你四个点,用前三个点绘制一个最小的圆,而这三个点必须在圆上或者在圆内,判断最一个点如 ...

  10. HDU 4720 Naive and Silly Muggles 平面几何

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...

随机推荐

  1. MATLAB 人脸定位

    faceimg = x222;faceDetector = vision.CascadeObjectDetector();bbox = step(faceDetector, faceimg);face ...

  2. Go 语言简介(上)— 语法

    周末天气不好,只能宅在家里,于是就顺便看了一下Go语言,觉得比较有意思,所以写篇文章介绍一下.我想写一篇你可以在乘坐地铁或公交车上下班时就可以初步了解一门语言的文章.所以,下面的文章主要是以代码和注释 ...

  3. [转]我花了一个五一终于搞懂了OpenLDAP

    轻型目录访问协议(英文:Lightweight Directory Access Protocol,缩写:LDAP)是一个开放的,中立的,工业标准的应用协议,通过IP协议提供访问控制和维护分布式信息的 ...

  4. go语言之进阶篇指针类型和普通类型的方法集

    方法集 类型的方法集是指可以被该类型的值调用的所有方法的集合. 用实例实例 value 和 pointer 调用方法(含匿名字段)不受方法集约束,编译器编总是查找全部方法,并自动转换 receiver ...

  5. [leetcode]Convert Sorted Array to Binary Search Tree @ Python

    原题地址:http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 题意:将一个排序好的数组转换为一颗二叉 ...

  6. python 数据处理中的 LabelEncoder 和 OneHotEncoder

    One-Hot 编码即独热编码,又称一位有效编码,其方法是使用N位状态寄存器来对N个状态进行编码,每个状态都由他独立的寄存器位,并且在任意时候,其中只有一位有效.这样做的好处主要有:1. 解决了分类器 ...

  7. Java基础(八):多态

    一.多态的理解: 多态是同一个行为具有多个不同表现形式或形态的能力. 多态就是同一个接口,使用不同的实例而执行不同操作,如图所示: 多态性是对象多种表现形式的体现:现实中,比如我们按下 F1 键这个动 ...

  8. Golang 中错误与异常需要重新认识

    如何进行错误处理,这是一个Go程序员之间,特别是一些新的Go程序员,会经常讨论的问题.讨论到最后往往由于以下代码的多次出现而变成了抱怨. if err != nil { return err } 我们 ...

  9. Jmeter测试报告可视化(Excel, html以及jenkins集成)

    做性能测试通常在none GUI的命令行模式下运行Jmeter. 例如: jmeter -n -t /opt/las/JMeter/TestPlan/test.jmx -l /opt/las/JMet ...

  10. 细说java中Map的两种迭代方式

    曾经对java中迭代方式总是迷迷糊糊的,今天总算弄懂了.特意的总结了一下.基本是算是理解透彻了. 1.再说Map之前先说下Iterator: Iterator主要用于遍历(即迭代訪问)Collecti ...