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. 数学图形之Breather surface

    这是一种挺漂亮的曲面图形,可惜没有找到太多的相关解释. In differential equations, a breather surface is a mathematical surface ...

  2. 用VLC读取摄像头产生RTSP流,DSS主动取流转发(一)(二) 【转】

    http://blog.csdn.net/fm0517/article/details/38110633 http://blog.csdn.net/fm0517/article/details/381 ...

  3. Android数字选择器-NumberPicker

    数字选择器NumberPicker是Android3.0之后引入的一个控件,比较常用,比如说手机常用的闹钟,可以选择小时和分钟,如果你需要兼容3.0之前版本,GitHub上有开源的项目,具体的下载地址 ...

  4. 【SpringCloud】Netflix源码解析之Ribbon:负载均衡策略的定义和实现

    Ribbon负载均衡策略定义 IRule其实就只做了一件事情Server choose(Object key),可以看到这个功能是在LB中定义(要求)的,LB把这个功能委托给IRule来实现.不同的I ...

  5. Android 如何修改默认输入法

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  6. NTP Server

    Network Time Protocol互联网时间协议 NTP is intended to synchronize all participating computers to within a ...

  7. RUP

    RUP随想 [摘要] 本文主要阐述一下我对RUP软件工程思想的看法以及一些感想.我认为软件工程既然是工程,那么纯粹的空谈理论是没有意义的,软件工程需要实干.我认为软件工程的思想实际上和兵法理论是一样的 ...

  8. Systemd 三部曲 之 PHP7

    安装编译php7时需要的依赖包 : yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-deve ...

  9. RS交叉表自动汇总后百分比列显示错误之解决方案

    可以说在从事Cognos开发的过程中,仅仅对数据展现而言,大多数用户使用最多的工具便是Report Studio了,此工具可以帮助我们快速的构建一些可供用户自主选择的数据报告.当然我个人认为没有什么开 ...

  10. Untracked Files Prevent Checkout move or commit them before checkout

    点开View Files... 查看里面的文件名称,在项目的.idea文件夹中删掉ViewFiles显示的文件夹名称就好