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. 22.线程通信Condition

    Condition     通过此对象可以与lock实现组合使用,为每个对象提供多个等待,实现多个阻塞队列. package dmeo9; import java.util.concurrent.lo ...

  2. poj 2585 Window Pains 解题报告

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2027   Accepted: 1025 Desc ...

  3. 第六章 企业项目开发--cookie

    注:本章代码基于<第五章 企业项目开发--mybatis注解与xml并用>的代码,链接如下: http://www.cnblogs.com/java-zhao/p/5120792.html ...

  4. iOS开发-iPad侧边栏Tab选项卡切换

    Android中习惯了叫侧边栏,iOS中如果不习惯侧边栏称呼的话可以叫dock,侧边栏的切换,类似于Android中的底部导航栏的切换,iPad尺寸大了一些,导航的栏目放在侧边会显示的更好耐看一些.选 ...

  5. web 实时通信的方法总结

    1.Web端即时通讯技术 即时通讯技术简单的说就是实现这样一种功能:服务器端可以即时地将数据的更新或变化反应到客户端,例如消息即时推送等功能都是通过这种技术实现的. 但是在Web中,由于浏览器的限制, ...

  6. LA 4728 Square ,旋转卡壳法求多边形的直径

    给出一些正方形.让你求这些正方形顶点之间的最大距离的平方. //返回点集直径的平方 int diameter2(vector<Point> & points) { vector&l ...

  7. ubuntu添加默认路由才可以访问网络

  8. COM的一些基本概念

      Windows lets you share code at the binary level using DLLs. After all, that's how Windows apps fun ...

  9. Java HashMap 默认排序

    先看一段Java代码. package com.m58.test; import java.text.ParseException; import java.text.SimpleDateFormat ...

  10. Java list 分页(多种方式)

    方式一:public static  void fenye(List list,int pagesize){    int totalcount=list.size();    int pagecou ...