Naive and Silly Muggles (计算几何)
Naive and Silly Muggles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 137 Accepted Submission(s): 94
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?
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.
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std; struct node
{
double x,y;
} point[];
double disA_B,disA_C,disB_C,Maxdis;//分别记录三边长和最长边
int a,b;//记录最长边的两个端点
double center_x,center_y;//最小圆的圆心坐标
double d;//记录圆心到该点的距离,与半径比较;
double radiu;//锐角三角形外接圆半径; void Distance()
{
disA_B = sqrt((point[].x-point[].x)*(point[].x-point[].x)+
(point[].y-point[].y)*(point[].y-point[].y));
disA_C = sqrt((point[].x-point[].x)*(point[].x-point[].x)+
(point[].y-point[].y)*(point[].y-point[].y));
disB_C = sqrt((point[].x-point[].x)*(point[].x-point[].x)+
(point[].y-point[].y)*(point[].y-point[].y)); if(disA_B >= disA_C && disA_B >= disB_C)
{
Maxdis = disA_B;
a = ;
b = ;
}
if(disA_C >= disA_B && disA_C >= disB_C)
{
Maxdis = disA_C;
a = ;
b = ;
}
if(disB_C >= disA_B && disB_C >= disA_C)
{
Maxdis = disB_C;
a = ;
b = ;
} }
//计算圆心到顶点的距离
double check(double x1,double y1,double x2,double y2)
{
double d;
d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
return d;
}
//判断三角形类型
int judge(double r1, double r2,double r3)
{
double res;
res = r1*r1+r2*r2-r3*r3;
if(res <= )
return true;//钝角或直角三角形
else return false;//锐角三角形
} int main()
{
int test;
scanf("%d",&test);
for(int t = ; t <= test; t++)
{
for(int i = ; i < ; i++)
scanf("%lf %lf",&point[i].x,&point[i].y); Distance(); printf("Case #%d: ",t); //三点在一条直线上,圆心在最长边的1/2处;
if(point[].x==point[].x && point[].x==point[].x)
{
center_x = (point[a].x+point[b].x)/2.0;
center_y = point[a].y;
d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,Maxdis/2.0);
if(d > Maxdis/2.0)
printf("Safe\n");
else printf("Danger\n");
//printf("在一条直线上\n");
}
else if(point[].y==point[].y && point[].y==point[].y)
{
center_x = point[a].x;
center_y = (point[a].y+point[b].y)/2.0;
d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,Maxdis/2.0);
if(d > Maxdis/2.0)
printf("Safe\n");
else printf("Danger\n");
//printf("在一条直线上\n");
} //钝角或直角三角形,圆心是最长边的1/2处,半径是最长边的一半;
else if(judge(disA_B,disA_C,disB_C) || judge(disA_B,disB_C,disA_C) || judge(disA_C,disB_C,disA_B))
{
center_x = (point[a].x+point[b].x)/2.0;
center_y = (point[a].y+point[b].y)/2.0;
d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,Maxdis/2.0);
if(d > Maxdis/2.0)
printf("Safe\n");
else printf("Danger\n");
//printf("是直角或钝角\n");
} //锐角三角形,圆心是外接圆的圆心;
else if(!judge(disA_B,disA_C,disB_C) && !judge(disA_B,disB_C,disA_C) && !judge(disA_C,disB_C,disA_B))
{
center_x = ;
center_y = ;
double x1 = point[].x;
double x2 = point[].x;
double x3 = point[].x;
double y1 = point[].y;
double y2 = point[].y;
double y3 = point[].y; center_x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(*(x3-x1)*(y2-y1)-*((x2-x1)*(y3-y1)));
center_y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(*(y3-y1)*(x2-x1)-*((y2-y1)*(x3-x1)));
radiu = sqrt((point[].x-center_x)*(point[].x-center_x)+(point[].y-center_y)*(point[].y-center_y)); d = check(center_x,center_y,point[].x,point[].y);
//printf("圆心(%lf,%lf),距离 = %lf,半径 = %lf\n",center_x,center_y,d,radiu);
if(d > radiu)
printf("Safe\n");
else printf("Danger\n");
//printf("是锐角\n"); } }
return ;
}
void circle_center(point[])
{
double x1,x2,x3,y1,y2,y3;
double radiu;//外接圆半径
double x = ;
double y = ; x1 = point[].x;
x2 = point[].x;
x3 = point[].x;
y1 = point[].y;
y2 = point[].y;
y3 = point[].y; //圆心坐标(x,y);
x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(*(x3-x1)*(y2-y1)-*((x2-x1)*(y3-y1)));
y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(*(y3-y1)*(x2-x1)-*((y2-y1)*(x3-x1)));
//半径
radiu = sqrt((point[].x - x)*(point[].x - x) + (point[].y - y)*(point[].y - y));
}
Naive and Silly Muggles (计算几何)的更多相关文章
- ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)
Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...
- 计算几何 HDOJ 4720 Naive and Silly Muggles
题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/a ...
- HDU 4720 Naive and Silly Muggles (简单计算几何)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- Naive and Silly Muggles
Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...
- HDU 4720 Naive and Silly Muggles (外切圆心)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Naive and Silly Muggles hdu4720
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU-4720 Naive and Silly Muggles 圆的外心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 先两两点之间枚举,如果不能找的最小的圆,那么求外心即可.. //STATUS:C++_AC_0M ...
- HDU 4720 Naive and Silly Muggles 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 题目大意:给你四个点,用前三个点绘制一个最小的圆,而这三个点必须在圆上或者在圆内,判断最一个点如 ...
- HDU 4720 Naive and Silly Muggles 平面几何
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...
随机推荐
- 亲测安装php
亲测安装php1.tar zvxf php-5.3.8.tar.gz 2.cd php-5.3.83../configure \ --prefix=/usr/local/php \--with-mys ...
- linux上传下载软件
如何实现windows和linux之间的文件传输 (原文地址:http://hi.baidu.com/ying5420/item/439dee93f0f7fd1a934f41e2) 如果想从windo ...
- android开发之broadcast学习笔记 分类: android 学习笔记 2015-07-19 16:33 32人阅读 评论(0) 收藏
android中的广播用的太多了,今天稍微总结一下. 按注册方式分为两种: 1.静态注册广播: 静态注册广播就是在androidManifest.xml文件中注册广播,假设我们要实现这样一个效果,在一 ...
- Java基础知识强化之集合框架笔记15:List集合的特点
1. List集合的特点 List本身也是一个接口,如下: public interface List<E> extends Collection<E> (1)List是有序的 ...
- javascript高级培训课程(一)
执行上下文 可执行代码类型-- 执行上下文类型 全局代码-- 全局上下文 函数代码-- 函数上下文 eval代码 -- eval上下文 arguments 超出传入参数个数的index 与形参不 ...
- c# 的导入功能SqlBulkCopy
private static void DataTableToSQLServer( DataTable dt) { string connectionString = GetConnectionStr ...
- Castle Windsor Fluent Registration API
一对一注册 直接注册组件 container.Register( Component.For<MyServiceImpl>() ); 注册接口并提供组件 container.Registe ...
- 关于“SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问 ”
原因:在从远程服务器复制数据到本地时出现“SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatas ...
- Angularjs总结(六) 上传附件
所用插件:angular-file-upload 这个插件用到的几个指令:nv-file-select(点击选择).uploader(用于绑定控制器中新建的uploader对象) HTML: < ...
- jQuery Callback 方法
Callback 函数在当前动画 100% 完成之后执行. jQuery 动画的问题 许多 jQuery 函数涉及动画.这些函数也许会将 speed 或 duration 作为可选参数. 例子:$(& ...