HDU 3007 Buried memory 最小圆覆盖
来源:互联网 发布:单片机如何检测电压 编辑:程序博客网 时间:2024/04/30 03:25
题目大意:没看。反正就是求最小圆覆盖。
思路:一个神奇的算法——随机增量法。可以证明,这个算法可以在O(n)的时间复杂度内求出最小圆覆盖。虽然好像能卡掉的样子,但是加上一句random_shuffle就卡不掉了。
具体的过程是这样的:
在全局记录一个圆,表示目前的最小圆覆盖。从头开始扫描。遇到第一个不在当前最小圆覆盖内的点的时候:
将这个点与当前最小圆覆盖的圆心为直径做一个圆,作为当前的最小圆覆盖。从头开始扫描。遇到第一个不在当前最小圆覆盖的点的时候:
将刚才的两个点和当前点做三角形,将这个三角形的外接圆作为当前的最小圆覆盖。
具体还是看代码吧,关于证明见:http://blog.csdn.net/lthyxy/article/details/6661250
CODE:
#define _CRT_SECURE_NO_WARNINGS#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 510using namespace std;struct Point{double x,y;Point(double _,double __):x(_),y(__) {}Point() {}Point operator +(const Point &a)const {return Point(x + a.x,y + a.y);}Point operator -(const Point &a)const {return Point(x - a.x,y - a.y);}Point operator *(double a)const {return Point(x * a,y * a);}void Read() {scanf("%lf%lf",&x,&y);}}point[MAX];inline double Calc(const Point &p1,const Point &p2){return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));}inline Point Mid(const Point &p1,const Point &p2){return Point((p1.x + p2.x) / 2,(p1.y + p2.y) / 2);}inline double Cross(const Point &p1,const Point &p2){return p1.x * p2.y - p1.y * p2.x;}inline Point Change(const Point &v){return Point(-v.y,v.x);}struct Circle{Point o;double r;Circle(const Point &_,double __):o(_),r(__) {}Circle() {}bool InCircle(const Point &p) {return Calc(p,o) <= r;}}now;struct Line{Point p,v;Line(const Point &_,const Point &__):p(_),v(__) {}Line() {}};inline Point GetIntersection(const Line &l1,const Line &l2){Point u = l1.p - l2.p;double t = Cross(l2.v,u) / Cross(l1.v,l2.v);return l1.p + l1.v * t;}int points;int main(){while(scanf("%d",&points),points) {for(int i = 1; i <= points; ++i)point[i].Read();random_shuffle(point + 1,point + points + 1);now = Circle(point[1],.0);for(int i = 2; i <= points; ++i)if(!now.InCircle(point[i])) {now = Circle(point[i],.0);for(int j = 1; j < i; ++j)if(!now.InCircle(point[j])) {now = Circle(Mid(point[i],point[j]),Calc(point[i],point[j]) / 2);for(int k = 1; k < j; ++k)if(!now.InCircle(point[k])) {Line l1(Mid(point[i],point[j]),Change(point[j] - point[i]));Line l2(Mid(point[j],point[k]),Change(point[k] - point[j]));Point intersection = GetIntersection(l1,l2);now = Circle(intersection,Calc(point[i],intersection));}}}printf("%.2lf %.2lf %.2lf\n",now.o.x,now.o.y,now.r);}return 0;}
0 0
- hdu 3007 Buried memory (最小圆覆盖)
- HDU 3007 Buried memory 最小圆覆盖
- HDU 3007 Buried memory (最小圆覆盖 凸包解法)
- HDOJ 3007 Buried memory 增量法最小圆覆盖
- [HDU3007]Buried memory(最小圆覆盖)
- Buried memory 简单几何之最小圆覆盖问题
- HDU 3007 Buried memory(点集最小圆覆盖 模拟退火解法)
- HDU 3007 Buried memory
- Buried memory(hdu 3007)
- HDU.3007 Buried memory
- HDU 3007:Buried memory
- HDU 3007 最小圆覆盖
- HDU 3007 最小圆覆盖
- acm hdu 3007 Buried memory
- hdu 3007 最小圆覆盖(模版)
- ZOJ 1450 HDU 3007 (最小圆覆盖)
- hdu 3007(最小圆覆盖)
- HDU 3007 Realtime Status 最小圆覆盖
- JLPT一级语法桌面(105条语法)
- 前台页面转入的数乱码,后台进行转码
- 9.HCNA-HNTD——VRP基础
- XCODE(IOS)下内嵌ARM汇编(ARM嵌入式开发中的GCC内联汇编)
- Linux内核启动过程学习
- HDU 3007 Buried memory 最小圆覆盖
- iOS多线程,NSThread ,NSOperationQueue ,GCD
- V8 javascript 引擎
- Android、iOS和Windows Phone中的推送技术
- 自动运行native2ascii 命令的Bat文件的编写
- Android之viewPager嵌套viewPager无法滑动子viewPager
- 访问者模式(Visitor)
- 对css hack的实践使用
- 前端样式控件