hdu3007Buried memory 最小圆覆盖 计算几何
来源:互联网 发布:ubuntu qq国际版 编辑:程序博客网 时间:2024/04/30 02:16
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007
Problem Description
Each person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.
The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters by the military exercises's opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let's help Sconbin to get the award.
The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters by the military exercises's opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let's help Sconbin to get the award.
Input
There are many test cases.Each case consists of a positive integer N(N<500,^V^,our great king might be a considerate lover) on a line followed by N lines giving the coordinates of N letters.Each coordinates have two numbers,x coordinate and y coordinate.N=0 is the end of the input file.
Output
For each case,there should be a single line in the output,containing three numbers,the first and second are x and y coordinates of the missile to launch,the third is the smallest radius the missile need to destroy all N letters.All output numbers are rounded to the second digit after the decimal point.
Sample Input
31.00 1.002.00 2.003.00 3.000
Sample Output
2.00 2.00 1.41
思路:穷举法,最小圆覆盖必然是某三个顶点的外界圆,那么设置三层循环进行枚举就可以了!
但是会出现下面的例外。
也就是说三层遍历得到C(n,3)个外接圆,并不能够保证算法的正确性,我们还要构造C(n,2)个以两个点的连线为直径的圆。
关于求解一个三角形的外接圆圆心:
我们只需找到两条线段的中垂线然后求交点即可。
代码:
#include<iostream> #include<cmath> #include<cstdio> #include<algorithm> using namespace std;const double eps = 1e-8;struct Point {double x, y;}p[505];double dis(const Point &a, const Point &b)//求距离{return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));}Point circumcenter(const Point &a, const Point &b, const Point &c)//返回三角形的外心 { Point ret;double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1) / 2;double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2) / 2;double d = a1*b2 - a2*b1;ret.x = a.x + (c1*b2 - c2*b1) / d;ret.y = a.y + (a1*c2 - a2*c1) / d;return ret;}void min_cover_circle(Point *p, int n, Point &c, double &r) { //c为圆心,r为半径 random_shuffle(p, p + n); // c = p[0]; r = 0;//圆心为第一个点 半径为0for (int i = 1; i<n; i++){if (dis(p[i], c)>r + eps) //第一个点 {c = p[i]; r = 0;//更改圆心for (int j = 0; j<i; j++)if (dis(p[j], c)>r + eps) //第二个点 {c.x = (p[i].x + p[j].x) / 2;//圆心暂时位于两点中间c.y = (p[i].y + p[j].y) / 2;r = dis(p[j], c);//半径更新for (int k = 0; k<j; k++)if (dis(p[k], c)>r + eps) //第三个点{c = circumcenter(p[i], p[j], p[k]);//求外接圆圆心,三点必不共线 r = dis(p[i], c);}}}}}int main() {int n;Point c;double r;while (scanf("%d", &n) == 1 && n) {for (int i = 0; i<n; i++)scanf("%lf%lf", &p[i].x, &p[i].y);min_cover_circle(p, n, c, r);printf("%.2lf %.2lf %.2lf\n", c.x, c.y, r);}return 0;}
0 0
- hdu3007Buried memory 最小圆覆盖 计算几何
- [计算几何笔记3]最小圆覆盖
- HDU 3932(计算几何+最小圆覆盖)
- HDU 4720(计算几何+最小圆覆盖)
- Buried memory 简单几何之最小圆覆盖问题
- bzoj1336/1337/2823 最小圆覆盖 计算几何
- 【BZOJ2823】【AHOI2012】信号塔 最小圆覆盖 计算几何
- bzoj1337 最小圆覆盖 计算几何 解题报告
- hdu 3007 Buried memory (最小圆覆盖)
- HDU 3007 Buried memory 最小圆覆盖
- [HDU3007]Buried memory(最小圆覆盖)
- HDOJ 3007 Buried memory 增量法最小圆覆盖
- HDU 3007 Buried memory (最小圆覆盖 凸包解法)
- 计算几何 三点求最小圆
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖
- 最小圆覆盖
- 如何设置vs窗口的属性管理器和解决方案管理器的位置
- Java之抽象类
- 【BZOJ 1036】树的统计Count(树链剖分)
- 编程基础知识科普:C#中的问号运算符
- 使用JavaScript与servlet实行简单的客户端和服务器验证
- hdu3007Buried memory 最小圆覆盖 计算几何
- 二分法查找
- freemarker用list函数循环列表并在指定位置跳出,即控制list循环个数
- 简单SQL语句执行用时
- 【59】按之字形顺序打印二叉树
- android菜鸟养成计划——adapter的简单应用
- gsoap入门:解决axis2服务器返回错误:com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "ns1"
- 数据结构与算法(4)顺序栈
- 商鞅变法与雅典革命