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. Strings of Power

    B. Strings of Power Volodya likes listening to heavy metal and (occasionally) reading. No wonder Vol ...

  2. 开发winform程序,在拖拽控件大小时,VS会卡死

    你可以看看你最近有没有装什么新的软件,比如说:有道词典就会与VS有冲突,导致卡死,可以把进程关闭.

  3. Gradle for Android 翻译 -1

    英文版电子书下载 参考:Gradle for Android  一.从 Gradle 和 AS 开始 [Getting Started with Gradle and Android Studio] ...

  4. 任务栈 启动模式 Task Flag launchMode MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  5. 亚马逊AWS免费套餐EC2安装centos连接登录并创建root

    前言:刚开始使用亚马逊的AWS的免费套餐EC2,由于个人习惯使用centos系统,所以果断安装,但是AWS为了安全性,默认禁止用户使用root账户,导致安装配置环境各种问题.所以我把从安好系统后遇到的 ...

  6. JSON在php中的使用

    从5.2版本开始,PHP原生提供json_encode()和json_decode()函数,前者用于编码,后者用于解码. json_encode()                           ...

  7. 【Python】Django数据模型、级联删除、级联更新、ER图导出等

    在本文中,我们将向读者详细介绍如何在更新和删除父表数据的同时,触发有关子表数据的级联更新和删除操作.您将看到当使用InnoDB表的时候,借助于外键约束就可以轻松搞定这一过程. 一.利用外键约束更新并删 ...

  8. 给 TextBlock 加 ToolTip

    <TextBlock ToolTip="{Binding RelativeSource={RelativeSource Self},Path=Text}" Text=&quo ...

  9. idea启动崩溃问题

    idea启动崩溃问题 内存已经给到1024m了: 注意到项目比较大,有个参数ReservedCodeCasheSize,把这个修改为1024m, 学习了:https://www.cnblogs.com ...

  10. (转)机器学习的数学基础(1)--Dirichlet分布

    转http://blog.csdn.net/jwh_bupt/article/details/8841644 这一系列(机器学习的数学基础)主要包括目前学习过程中回过头复习的基础数学知识的总结. 基础 ...