HDU 4720(计算几何+最小圆覆盖)
来源:互联网 发布:u盘必装软件 编辑:程序博客网 时间:2024/04/30 06:42
问题描述:
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 x iand y i (|x i, y i| <= 10), indicating the three wizards' positions. Then a single line with two numbers q x and q y (|q x, q y| <= 10), indicating the muggle's position.
Output
For test case X, output "Case #X: " first, then output "Danger" or "Safe".
Sample Input
30 02 01 21 -0.50 02 01 21 -0.60 03 01 11 -1.5Sample Output
Case #1: DangerCase #2: SafeCase #3: Safe
题目题意:题目可以给我们四个点,问第四个点,在不在前三个点的最小覆盖圆里。
题目分析:直接求出圆心和半径,然后用圆心到第四个点的距离与半径比较就行。
有覆盖圆的模板就是好!
代码如下:
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>using namespace std;const double epx=1e-7;struct Point{ double x,y;};struct Point a[1005],d;double r;double get_dis(Point p1,Point p2) //两点间距离{ return (sqrt((p1.x-p2.x)*(p1.x -p2.x)+(p1.y-p2.y)*(p1.y-p2.y)));}double get_muti(Point p1, Point p2,Point p0){ return ((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));}void get_o(Point p,Point q,int n){ d.x=(p.x+q.x)/2.0; d.y=(p.y+q.y)/2.0; r=get_dis(p,q)/2; int k; double c1,c2,t1,t2,t3; for(k=1;k<=n;k++) { if(get_dis(d,a[k])<=r)continue; if(get_muti(p,q,a[k])!=0.0) { c1=(p.x*p.x+p.y*p.y-q.x*q.x-q.y*q.y)/2.0; c2=(p.x*p.x+p.y*p.y-a[k].x*a[k].x-a[k].y*a[k].y)/2.0; d.x=(c1*(p.y-a[k].y)-c2*(p.y-q.y))/((p.x-q.x)*(p.y-a[k].y)-(p.x-a[k].x)*(p.y-q.y)); d.y=(c1*(p.x-a[k].x)-c2*(p.x-q.x))/((p.y-q.y)*(p.x-a[k].x)-(p.y-a[k].y)*(p.x-q.x)); r=get_dis(d,a[k]); } else { t1=get_dis(p,q); t2=get_dis(q,a[k]); t3=get_dis(p,a[k]); if(t1>=t2&&t1>=t3) { d.x=(p.x+q.x)/2.0; d.y=(p.y+q.y)/2.0;r=get_dis(p,q)/2.0; } else if(t2>=t1&&t2>=t3) { d.x=(a[k].x+q.x)/2.0; d.y=(a[k].y+q.y)/2.0; r=get_dis(a[k],q)/2.0; } else { d.x=(a[k].x+p.x)/2.0; d.y=(a[k].y+p.y)/2.0; r=get_dis(a[k],p)/2.0; } } }}void solve(Point pi,int n)//求最小覆盖圆{ d.x=(pi.x+a[1].x)/2.0; d.y=(pi.y+a[1].y)/2.0; r=get_dis(pi,a[1])/2.0; int j; for(j=2;j<=n;j++){ if(get_dis(d,a[j])<=r)continue; else get_o(pi,a[j],j-1); }}int main(){ int t,icase=1; scanf("%d",&t); while (t--) { for (int i=1;i<=3;i++) { scanf("%lf%lf",&a[i].x,&a[i].y); } struct Point p; scanf("%lf%lf",&p.x,&p.y); r=get_dis(a[1],a[2])/2.0; d.x=(a[1].x+a[2].x)/2.0; d.y=(a[1].y+a[2].y)/2.0; for(int i=3;i<=3;i++){ if(get_dis(d,a[i])<=r)continue; else solve(a[i],i-1); } if (get_dis(p,d)-r<epx) printf("Case #%d: Danger\n",icase++); else printf("Case #%d: Safe\n",icase++); } return 0;}
- HDU 4720(计算几何+最小圆覆盖)
- HDU 3932(计算几何+最小圆覆盖)
- [计算几何笔记3]最小圆覆盖
- hdu3007Buried memory 最小圆覆盖 计算几何
- bzoj1336/1337/2823 最小圆覆盖 计算几何
- 【BZOJ2823】【AHOI2012】信号塔 最小圆覆盖 计算几何
- bzoj1337 最小圆覆盖 计算几何 解题报告
- HDU 3007 最小圆覆盖
- hdu 2215(最小圆覆盖)
- HDU 3007 最小圆覆盖
- hdu 3007 最小圆覆盖(模版)
- hdu 3007 Buried memory (最小圆覆盖)
- HDU 3007 Buried memory 最小圆覆盖
- ZOJ 1450 HDU 3007 (最小圆覆盖)
- hdu 3007(最小圆覆盖)
- HDU 3007 Realtime Status 最小圆覆盖
- Buried memory 简单几何之最小圆覆盖问题
- 计算几何 三点求最小圆
- 最多约束问题
- AndroidTv Home界面实现原理(二)——Leanback 库的主页卡位缩放动画源码解析
- 重载双目/单目运算符
- Swift 判断是否为<null>
- bzoj1602[Usaco2008 Oct]牧场行走(lca模版)
- HDU 4720(计算几何+最小圆覆盖)
- php实现限制文件下载速度
- 懒人开发之 NiceDialog
- 刷题五
- C++引用
- C#HttpClient返回乱码的解决方案
- 教你如何迅速秒杀掉:99%的海量数据处理面试题
- csi摄像头 raspistill常用命令
- php中引用&的真正理解-变量引用、函数引用、对象引用