HDU 4720 :Naive and Silly Muggles

题目:HDU 4720 :Naive and Silly Muggles

题目大意:这题的意思是给出三个点, 然后在给出另一个点,问这个点会不会在覆盖前面三个点的最小的圆里面(包括边界), 在里面最输出danger, 如果任何情况下这个点都不在圆里面,那么就输出safe。

解题思路:三个点最小的覆盖的圆是三角形的外接圆,这样的圆面积一定是最小的。 但是相同面积的圆,所在的位置,覆盖的点会是不一样的。例如垂心关于三条边的对称点,以某个对称点为圆心的圆用之前的半径做圆,如果能够覆盖原来的三个点(点可能在内部也可能在边界),这样的圆也是可以的,这样的圆和之前的圆位置就不一样了, 所覆盖的点也是不一样的。

代码:

#include <stdio.h>
#include <math.h>

const double esp = 1e-9;

struct POINT {

	double x, y;
}point[4], center;

struct LINE {

	double a, b, c;
};

LINE getline (POINT p1, POINT p2) {

	LINE l;
	l.a = (p2.y - p1.y);
	l.b = (p1.x - p2.x);
	l.c = p1.x * p2.y - p2.x * p1.y;
	return l;
}
//两条直线的交点
POINT inter_point (LINE l1, LINE l2) {

	POINT p;
	p.y = (l2.a * l1.c - l1.a * l2.c) / (l2.b * l1.a - l2.a * l1.b);
	p.x = (l1.c * l2.b - l2.c * l1.b) / (l2.a * l1.b - l2.b * l1.a);
	return p;
}
//外界圆的圆心
POINT circle_p (POINT p1, POINT p2, POINT p3 ) {

	POINT p;
	double a = p2.x - p1.x;
	double b = p2.y - p1.y;
	double c = p2.y * p2.y - p1.y * p1.y + p2.x * p2.x - p1.x * p1.x;
	double d = p3.x - p1.x;
	double e = p3.y - p1.y;
	double f = p3.y * p3.y - p1.y * p1.y + p3.x * p3.x - p1.x * p1.x;
	p.y = (f * a - c * d) / (e * a - b * d) * 0.5;
	p.x = (c - 2 * p.y * b) / (2 * a);
	return p;

}

double dis (POINT p1, POINT p2) {

	double dx = p1.x - p2.x;
	double dy = p1.y - p2.y;
	return sqrt (pow (dx, 2) + pow (dy, 2));
}

bool solve () {

	double r = dis (center , point[0]);
	if (dis (center , point[3]) - r > esp)
		return false;
	LINE l1, l2;
	POINT p;
	int t;
	for (int i = 0; i < 3; i++) {

		t = (i + 2) % 3;
		l1 = getline (point[i], point[( i + 1 ) % 3]);
		l2.a = l1.b;
		l2.b = -l1.a;
		l2.c = l1.a * center.y - l1.b * center.x;
		p = inter_point (l1, l2);
		p.x = (p.x * 2 - center.x);
		p.y = (p.y * 2 - center.y);
		if (dis (p, point[t]) - r > esp)
			continue;
		if (dis (p, point[3]) - r > esp)
			return false;
	}
	return true;
}

int main () {

	int t;
	double x, y;
	scanf ("%d", &t);
	for (int i = 1; i <= t; i++) {

		for (int j = 0; j < 4; j++) {

			scanf ("%lf%lf", &x, &y);
			point[j].x = x;
			point[j].y = y;
		}
		center = circle_p(point[0], point[1], point[2]);
		printf ("Case #%d: %s\n", i, solve()?"Danger":"Safe");
	}
	return 0;
}

HDU 4720 :Naive and Silly Muggles,布布扣,bubuko.com

时间: 2024-10-06 09:13:39

HDU 4720 :Naive and Silly Muggles的相关文章

hdu 4720 Naive and Silly Muggles(几何)

题目链接:hdu 4720 Naive and Silly Muggles 题目大意:给出三点,找出一个圆,要求面积尽量小,并且三点必须在园内,如果可以找到一个圆,使得说第4个点不在圆内则是安全的. 解题思路:面积最小即三个点外切圆,根据三角形两条边的垂直平分线求出圆心.判断第4个点是否在圆内只要计算距离即可. 然后还要考虑说面积和外切圆相同,但是圆心不同的圆. #include <cstdio> #include <cstring> #include <cmath>

计算几何 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

hdu4720Naive and Silly Muggles

链接 一直理解的最小覆盖圆就是外接圆..原来还要分钝角和锐角... 钝角的话就为最长边的中点,对于这题分别枚举一下外接圆以及中点的圆,判一下是不是在园外. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmat

HDU-DuoXiao第二场hdu 6315 Naive Operations 线段树

hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线段树,一开始没用lazy,TLE了,然后开始想lazy的标记,这棵线段树的特点是,每个节点维护 :一个区间某个a 要增加1所需个数的最小值,一个区间已加上的mx的最大值标记,还有就是区间和sum. (自己一开始没有想到mx标记,一度想把lazy传回去. (思路差一点就多开节点标记. #include

HDU 6315: Naive Operations

Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)Total Submission(s): 1791    Accepted Submission(s): 772 Problem Description In a galaxy far, far away, there are two integer sequence a and b of le