hdu 3995 Perfect Faceless Void

昨天看这题就在想怎么和最小圆覆盖结合一起,不过没信心写 = =。。

昨晚搜题解,有人发布官方标程了,还真是结合最小圆覆盖了。

我还是对最小圆覆盖理解不好啊。。。把我的改了改,就过了。

二者一起算,如果碰到在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 == y
double 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值