HDU 4720 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): 24 Accepted Submission(s): 17
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.
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
Case #2: Safe
Case #3: Safe
首先是找出一个最小的圆来覆盖三个点。
圆心要么是三条线段的中点,或者三角形的外心,很容易找出来。‘
然后判断点是否在圆外就可以了
/* ***********************************************
Author :kuangbin
Created Time :2013-9-11 13:17:28
File Name :2013-9-11\1005.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps)return ;
if ( x < )return -;
else return ;
}
struct Point
{
double x,y;
Point(double _x = , double _y = )
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
};
double dist(Point a,Point b)
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
} //过三点求圆心坐标
Point waixin(Point a,Point b,Point c)
{
double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/;
double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/;
double d = a1*b2 - a2*b1;
return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 -a2*c1)/d);
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int iCase = ;
Point p[];
scanf("%d",&T);
while(T--)
{
iCase++;
for(int i = ;i < ;i++)
p[i].input();
Point res;
double tmp = 1e20;
for(int i = ;i < ;i++)
{
Point t = Point((p[i].x+p[(i+)%].x)/,(p[i].y+p[(i+)%].y)/);
double dd = max(dist(p[],t),max(dist(p[],t),dist(p[],t)));
if(dd < tmp)
{
tmp = dd;
res = t;
}
}
if(sgn( (p[]-p[])^(p[]-p[]) ) != )
{
Point t = waixin(p[],p[],p[]);
double dd = max(dist(p[],t),max(dist(p[],t),dist(p[],t)));
if(dd < tmp)
{
tmp = dd;
res = t;
} }
printf("Case #%d: ",iCase);
if(sgn(tmp - dist(res,p[])) >= )
printf("Danger\n");
else printf("Safe\n");
}
return ;
}
HDU 4720 Naive and Silly Muggles (简单计算几何)的更多相关文章
- HDU 4720 Naive and Silly Muggles (外切圆心)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 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 解题报告:给出一个三角形的三个顶点坐标,要求用一个最小的圆将这个三个点都包含在内,另外输入一个点 ...
- 计算几何 HDOJ 4720 Naive and Silly Muggles
题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/a ...
- Naive and Silly Muggles (计算几何)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)
Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...
- Naive and Silly Muggles
Problem Description Three wizards are doing a experiment. To avoid from bothering, a special magic i ...
- 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 ...
随机推荐
- 查找Python包的依赖包(语句)
Window 10家庭中文版,Python 3.6.4, 今天看完了urllib3的官文(官方文档),因为没有具体使用过,所以,仍然是一知半解,但是,突然想知道 urllib3以及前面学习过的requ ...
- Python开发环境(2):启动Eclipse时检测到PYTHONPATH发生改变
OS:Windows 10家庭中文版,Eclipse:Oxygen.1a Release (4.7.1a),PyDev:6.3.2 4月25日,在Eclipse上安装了PyDev(前面博文有记录),并 ...
- C# byte[] 转换16进制字符串
1.byte[] 转换16进制字符串 1.1 BitConverter方式 var str = DateTime.Now.ToString(); var encode = Encoding.UTF8; ...
- 金融数据分析 - 利用 Tushare Pro 平台 获取金融数据
Tushare金融大数据开放社区 免费提供各类金融数据和区块链数据 , 助力智能投资与创新型投资. 详见 https://tushare.pro/
- python基础--hashlib模块
hashlib模块用于加密操作,代替了md5和sha模块, 主要提供SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法. # -*- coding:utf-8 - ...
- pyquery学习笔记
很早就听说了pyquery的强大.写了个简单的测试程序实验下. 思路是找个动态网页,先用PhantomJS加载,然后用PYQUERY解析. 1.随便找了个带表格的股票网页,里面有大量的股票数据,测试的 ...
- java 二叉树遍历
package com.lever; import java.util.LinkedList;import java.util.Queue; /** * 二叉树遍历 * @author lckxxy ...
- bms_output.put_line使用方法
https://blog.csdn.net/sxww321/article/details/4020300
- oracle查看所有表及各表行数
https://zhidao.baidu.com/question/131972827.html
- Ionic实战五:ionic图表源码基于highcharts
ionic图表demo基于Highcharts,highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表.HighCha ...