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. tornado基础入门(一)——简单了解tornado

    参考:http://demo.pythoner.com/itt2zh/ch1.html tornado是一个轻量级的web框架,是一个用python写的web服务器,它有三个最大的特点(优势)速度.简 ...

  2. kafak-python函数使用详解

    Consumer是非线程安全的 Kafka只保证消息不漏,即at lease once,而不保证消息不重.关键点:假如consumer挂了重启,那它将从committed offset位置(告诉ser ...

  3. iOS:转载:UIControl的使用

    主要功能: UIContol(控件是所有控件的基类 如:(UIButton)按钮主要用于与用户交互,通常情况下我们不会直接使用UIControl,而是子类化它. 常用属性: BOOL enabled ...

  4. 附2 hystrix详述(2)- 配置

    一.hystrix在生产中的建议 1.保持timeout的默认值(1000ms),除非需要修改(其实通常会修改) 2.保持threadpool的的线程数为10个,除非需要更多 3.依赖标准的报警和监控 ...

  5. 几行JavaScript代码搞定Iframe 自动适应

    场景:Iframe嵌入flash,希望flash能随着页面的resize而resize. 主要代码: 代码 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTM ...

  6. HDU 4576 Robot (概率DP)

    暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...

  7. poj 2135 (基础费用流)

    题意:从1到n再到1,每条边只能走一次,求最短距离. 建图:每条边只能走一次就是流量是1,添加源点与1相连,容量为2,费用为0,n与汇点相连容量为2,费用为0: 求增广路用SPFA最短路求,, #in ...

  8. OC 创建单例

    static BlockBackground *_sharedInstance = nil; + (BlockBackground*)sharedInstance { if (_sharedInsta ...

  9. 【DevOps】为什么我们永远疲于奔命?

    作者:范军 (Frank Fan) 新浪微博:@frankfan7   微信:frankfan7 在[DevOps]谁说大象不能跳舞?一文之后,本文对DevOps的理念作进一步探讨. 最近在读一本书& ...

  10. 微信小程序 - 使用npm(第三方包)

    使用示例: 1. 开启“使用npm模块” 2. 新建 node_modules 文件夹 3. cd到新建 node_modules 所在的目录(非node_modules文件夹内) npm insta ...