hdu 4720 Naive and Silly Muggles(几何)

题目链接:hdu 4720 Naive and Silly Muggles

题目大意:给出三点,找出一个圆,要求面积尽量小,并且三点必须在园内,如果可以找到一个圆,使得说第4个点不在圆内则是安全的。

解题思路:面积最小即三个点外切圆,根据三角形两条边的垂直平分线求出圆心。判断第4个点是否在圆内只要计算距离即可。

然后还要考虑说面积和外切圆相同,但是圆心不同的圆。

#include <cstdio>
#include <cstring>
#include <cmath>

const double eps = 1e-9;

struct point  {
	double x, y;
}p[3], o, e;

struct line {
	double A, B, C;
}l[3];

inline double dis (double x, double y) {
	return x * x + y * y;
}

line getline (double a, double b, double x, double y) {
	line cur;
	cur.A = a;
	cur.B = b;
	cur.C = -(a*x + b*y);
	return cur;
}

point getP(line a, line b) {
	point cur;
	cur.x = (b.C*a.B - a.C*b.B)/(a.A*b.B - b.A*a.B);
	cur.y = (b.C*a.A - a.C*b.A)/(a.B*b.A - b.B*a.A);
	return cur;
}

void init () {
	for (int i = 0; i < 3; i++)
		scanf("%lf%lf", &p[i].x, &p[i].y);

	for (int i = 0; i < 3; i++)
		l[i] = getline(p[i].x - p[i+1].x, p[i].y - p[i+1].y, (p[i].x+p[i+1].x)/2, (p[i].y+p[i+1].y)/2);
	scanf("%lf%lf", &e.x, &e.y);

	o = getP(l[0], l[1]);
}

bool judge () {
	double r = dis(o.x - p[0].x, o.y - p[0].y);
	point oo;

	double d = dis(o.x - e.x, o.y - e.y);
	if (d > r)
		return false;

	for (int i = 0; i < 3; i++) {
		int k = (i+1)%3;
		int t = 3 - i - k;

		line a = getline(p[k].y - p[i].y, p[i].x - p[k].x, p[i].x, p[i].y);
		line b = getline(p[i].x - p[k].x, p[i].y - p[k].y, o.x, o.y);
		point cur = getP(a, b);

		oo.x = 2*cur.x - o.x;
		oo.y = 2*cur.y - o.y;

		if (dis(oo.x - p[t].x, oo.y - p[t].y) > r)
			continue;

		if (dis(oo.x - e.x, oo.y - e.y) > r)
			return false;
	}
	return true;
}

int main () {
	int cas;
	scanf("%d", &cas);
	for (int i = 1; i <= cas; i++) {
		init ();
		printf("Case #%d: %s\n", i, judge() ? "Danger" : "Safe");
	}
	return 0;
}

hdu 4720 Naive and Silly Muggles(几何)

时间: 2024-08-26 11:36:01

hdu 4720 Naive and Silly Muggles(几何)的相关文章

HDU 4720 :Naive and Silly Muggles

题目:HDU 4720 :Naive and Silly Muggles 题目大意:这题的意思是给出三个点, 然后在给出另一个点,问这个点会不会在覆盖前面三个点的最小的圆里面(包括边界), 在里面最输出danger, 如果任何情况下这个点都不在圆里面,那么就输出safe. 解题思路:三个点最小的覆盖的圆是三角形的外接圆,这样的圆面积一定是最小的. 但是相同面积的圆,所在的位置,覆盖的点会是不一样的.例如垂心关于三条边的对称点,以某个对称点为圆心的圆用之前的半径做圆,如果能够覆盖原来的三个点(点可

计算几何 HDOJ 4720 Naive and Silly Muggles

题目传送门 /* 题意:给三个点求它们的外接圆,判断一个点是否在园内 计算几何:我用重心当圆心竟然AC了,数据真水:) 正解以后补充,http://www.cnblogs.com/kuangbin/archive/2013/09/11/3315055.html */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string

HDOJ 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): 700    Accepted Submission(s): 451 Problem Description Three wizards are doing a exper

Naive and Silly Muggles(计算几何 判断点是否在三点形成的最小圆内)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4720 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

ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)

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

HDU 4720

http://acm.hdu.edu.cn/showproblem.php?pid=4720 包含三个点且最小的圆可能是三角形的外接圆或者是以任意两点连成线段的中点为圆心的园,找出最小的即可,然后判断麻瓜到圆心的距离和圆半径之间的关系,注意求外心的前提是三点不共线 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm&g

hdu 1577 WisKey的眼神 (数学几何)

WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2059    Accepted Submission(s): 625 Problem Description WisKey的眼镜有500多度,所以眼神不大好,而且他有个习惯,就是走路喜欢看着地(不是为了拣钱哦^_^),所以大家下次碰见他的时候最好主动打下招呼,呵呵.但是

hdu 1115 Lifting the Stone (数学几何)

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5203    Accepted Submission(s): 2155 Problem Description There are many secret openings in the floor which are covered by a big

hdu 1700 Points on Cycle 水几何

已知圆心(0,0)圆周上的一点,求圆周上另外两点使得三点构成等边三角形. 懒得推公式,直接用模板2圆(r1=dist,r2=sqrt(3)*dist)相交水过 #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<iterator> using namespace std; #define eps 1e-6 typedef long lon