bzoj 1337 最小圆覆盖
2015-06-03 15:36
309 查看
/************************************************************** Problem: 1337 User: idy002 Language: C++ Result: Accepted Time:4 ms Memory:2372 kb ****************************************************************/ #include <cstdio> #include <cmath> #include <algorithm> #define line(a,b) ((b)-(a)) #define eps 1e-10 #define N 100010 using namespace std; int sg( double x ) { return (x>-eps)-(x<eps); } struct Vector { double x, y; Vector( double x=0, double y=0 ):x(x),y(y){} Vector operator+( const Vector &b ) const { return Vector(x+b.x,y+b.y); } Vector operator-( const Vector &b ) const { return Vector(x-b.x,y-b.y); } Vector operator*( double b ) const { return Vector(x*b,y*b); } Vector operator/( double b ) const { return Vector(x/b,y/b); } double operator^( const Vector &b ) const { return x*b.y-y*b.x; } double len() { return sqrt(x*x+y*y); } Vector nor() { return Vector(-y,x); } }; typedef Vector Point; Point inter( Point p, Vector u, Point q, Vector v ) { return p+u*((line(p,q)^v)/(u^v)); } struct Circle { Point o; double r; Circle(){} Circle( Point a ):o(a),r(0){} Circle( Point a, Point b ) { o = (a+b)/2; r = (a-b).len()/2; } Circle( Point a, Point b, Point c ) { // ab^bc != 0 Point p=(a+b)/2, q=(b+c)/2; Vector u=(a-b).nor(), v=(b-c).nor(); o = inter(p,u,q,v); r = (o-a).len(); } bool contain( Point a ) { return sg( (a-o).len() - r ) <= 0; } }; int n; Point pts ; int main() { scanf( "%d", &n ); for( int i=1; i<=n; i++ ) { double x, y; scanf( "%lf%lf", &x, &y ); pts[i] = Point(x,y); } random_shuffle( pts+1, pts+1+n ); Circle c = Circle(pts[1]); for( int i=2; i<=n; i++ ) { if( c.contain(pts[i]) ) continue; c = Circle(pts[i]); for( int j=1; j<i; j++ ) { if( c.contain(pts[j]) ) continue; c = Circle(pts[i],pts[j]); for( int k=1; k<j; k++ ) { if( c.contain(pts[k]) ) continue; c = Circle(pts[i],pts[j],pts[k]); } } } printf( "%.3lf\n", c.r ); }
View Code
题解见bzoj 1336
相关文章推荐
- wap 笔试题2015
- 无Mac机IOS开发环境搭建手记
- 数据库查询效率优化
- HDU 1671 (Trie 字典树)
- Leetcode Problem.202—Happy Number
- 文章标题
- CSS设置水平居中和垂直居中
- sql select 执行顺序
- local variable 'xxx' referenced before assignment
- 转载:Android自动化测试- 自动获取短信验证码
- 批量数据库还原
- JS setTimeout()学习笔记
- 宏定义,const 与 sizeof
- UIWindow介绍
- Android开发规范
- 给socks-proxy-agent增加认证
- HTML5定稿了,为什么原生App世界将被颠覆
- log4j配置
- img标签中src包含data URL scheme-在一个URL中包含图片数据
- PHP的包依赖管理工具Composer简介