hdu 3995 Perfect Faceless Void
来源:互联网 发布:神鸟数据咨询有限公司 编辑:程序博客网 时间:2024/06/10 12:35
昨天看这题就在想怎么和最小圆覆盖结合一起,不过没信心写 = =。。
昨晚搜题解,有人发布官方标程了,还真是结合最小圆覆盖了。
我还是对最小圆覆盖理解不好啊。。。把我的改了改,就过了。
二者一起算,如果碰到在m那个集合里的点,如果在内部,就让它作为边界点即可。
#include <set>#include <map>#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>#define MID(x,y) ( ( x + y ) >> 1 )#define L(x) ( x << 1 )#define R(x) ( x << 1 | 1 )#define FOR(i,s,t) for(int i=s; i<t; i++)#define BUG puts("here!!!")using namespace std;const int MAX = 20010;struct point { double x,y;bool f;void get() { scanf("%lf%lf", &x, &y); }};point p[MAX];const double eps = 1e-6;bool dy(double x,double y){return x > y + eps;}// x > y bool xy(double x,double y){return x < y - eps;}// x < y bool dyd(double x,double y){ return x > y - eps;}// x >= y bool xyd(double x,double y){return x < y + eps;} // x <= y bool dd(double x,double y) {return fabs( x - y ) < eps;} // x == ydouble disp2p(point a,point b) // a b 两点之间的距离 {return sqrt( ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) );}point circumcenter(point a,point b,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){random_shuffle(p,p+n);// #include <algorithm>c = p[0]; r = 0;for(int i=1; i<n; i++)if( dy(disp2p(p[i],c),r) && p[i].f || xy(disp2p(p[i],c),r) && !p[i].f ){c = p[i];r = 0;for(int k=0; k<i; k++)if( dy(disp2p(p[k],c),r) && p[k].f || xy(disp2p(p[k],c),r) && !p[k].f ){c.x = (p[i].x + p[k].x)/2;c.y = (p[i].y + p[k].y)/2;r = disp2p(p[k],c);for(int j=0; j<k; j++)if( dy(disp2p(p[j],c),r) && p[j].f || xy(disp2p(p[j],c),r) && !p[j].f ){// 求外接圆圆心,三点必不共线 c = circumcenter(p[i],p[k],p[j]);r = disp2p(p[i],c);}}}}int main(){int n, m;while( ~scanf("%d%d", &n, &m) ){FOR(i, 0, n){p[i].get();p[i].f = true;}FOR(i, n, n+m){p[i].get();p[i].f = false;}point c; double r;min_cover_circle(p, n+m, c, r);printf("%.3lf %.3lf\n%.3lf\n", c.x, c.y, r);}return 0;}
- hdu 3995 Perfect Faceless Void
- hdu 3524 Perfect Squares
- hdu 1334 Perfect Cubes
- HDU 1334 Perfect Cubes
- "Perfect"
- HDU 1334 Perfect Cubes【穷举法】
- HDU 3524 Perfect Squares 数学找规律
- 杭电 HDU ACM 1334 Perfect Cubes
- hdu 3524 Perfect Squares 推公式求逆元
- HDU 1334 Perfect Cubes
- PDF文档解析java Big Faceless
- void *
- void
- void
- void
- void
- void
- void*
- AVR开发I/O与中断
- 近端时间开发一个winfrom项目和as 3.0的结合,费了老大劲了
- 大四了
- Win2008 IE 增强的安全配置概述IE ESC
- 鼠标移上去显示提示jquery
- hdu 3995 Perfect Faceless Void
- 《那些年啊,那些事——一个程序员的奋斗史》——27
- jquery ajax 全面解析
- (转).Net技巧:ASP.NET获取网站路径
- 排序算法之三 2-路插入排序
- cocos2dx linux and android project in eclipse
- 将access导入SQL server
- poj 1061(线性同余方程。。。。)
- Android开发环境的搭建两步走(一)