hdu3007(最小包围圆/最小覆盖圆)

这个。。初看这个题型竟然看成最小包围圈= =!

然后算法感觉比较奇怪。。叫什么随机增量法。。不过个人感觉是暴力枚举吧。。

由于3点确定一圆,所以枚举3个点,如果有点在圆外那么加入该点之后该点必定在覆盖圆上。。

然后据说这方法的时间复杂度的期望是O(n)。。。给窝感觉却不止o(n)。。证明看不懂。。



实际上貌似真的没那么快。。。500都跑60ms是闹哪样?

然后求圆心的方法也比较奇怪。。估计是推完公式后直接整理出来的。。就直接当结论用了,懒得证。。

所以总体来讲就是一个板子。。背!




/**
 *        ┏┓    ┏┓ 
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃   
 *        ┃   ━    ┃ 
 *        ┃ >   < ┃ 
 *        ┃       ┃ 
 *        ┃... ⌒ ...  ┃ 
 *        ┃       ┃ 
 *        ┗━┓   ┏━┛ 
 *          ┃   ┃ Code is far away from bug with the animal protecting           
 *          ┃   ┃   神兽保佑,代码无bug 
 *          ┃   ┃            
 *          ┃   ┃         
 *          ┃   ┃ 
 *          ┃   ┃            
 *          ┃   ┗━━━┓ 
 *          ┃       ┣┓ 
 *          ┃       ┏┛ 
 *          ┗┓┓┏━┳┓┏┛ 
 *           ┃┫┫ ┃┫┫ 
 *           ┗┻┛ ┗┻┛ 
 */  
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 400005
#define nm 1000498
#define pi 3.1415926535897931
using namespace std;
const ll inf=1e9;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}










struct P{
	double x,y;
	P(double x=0,double y=0):x(x),y(y){}
	P operator+(const P&o){return P(x+o.x,y+o.y);}
	P operator-(const P&o){return P(x-o.x,y-o.y);}
	double operator*(const P&o){return x*o.y-y*o.x;}
	P operator/(const double&t){return P(x/t,y/t);}
}p[NM],c;
double dis(P o){return sqrt(sqr(o.x)+sqr(o.y));}
int n;
double r;
P cir(P a,P b,P c){
	P p1=b-a,p2=c-a;
	double t=p1*p2,t1=(sqr(p1.x)+sqr(p1.y))/2,t2=(sqr(p2.x)+sqr(p2.y))/2;
	if(fabs(t)<eps){
		t=dis(b-c);t1=dis(p1);t2=dis(p2);
		if(t1>t2&&t1>t)return (a+b)/2;
		if(t2>t)return (a+c)/2;
		return (b+c)/2;
	}
	return a+P(t1*p2.y-t2*p1.y,t2*p1.x-t1*p2.x)/t;
}

void mcc(){
	random_shuffle(p,p+n);
	c=p[1];r=0;
	inc(i,2,n)if(dis(p[i]-c)>r+eps){
		c=p[i];r=0;
		inc(j,1,i-1)if(dis(p[j]-c)>r+eps){
			c=(p[i]+p[j])/2;r=dis(p[i]-c);
			inc(k,1,j-1)if(dis(p[k]-c)>r+eps){
				c=cir(p[i],p[j],p[k]);
				r=dis(p[i]-c);
			}
		}
	}
}

int main(){
	//freopen("data.in","r",stdin);
	while(n=read()){
		inc(i,1,n)scanf("%lf%lf",&p[i].x,&p[i].y);
		mcc();
		printf("%.2lf %.2lf %.2lf\n",c.x,c.y,r);
	}
	return 0;
}






Buried memory

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3698    Accepted Submission(s): 1974


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.
 

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
 
 
3 1.00 1.00 2.00 2.00 3.00 3.00 0
 

Sample Output
 
 
2.00 2.00 1.41
 

Source
 

Recommend
gaojie   |   We have carefully selected several similar problems for you:   3004  3001  3002  3003  3006 
 

Statistic |  Submit |  Discuss | Note

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值