为什么我的代码没有被卡精度?
查看原帖
为什么我的代码没有被卡精度?
848868
Kuroba_kaito楼主2024/12/16 11:05
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
struct point{
	double x,y;
}p[N];
struct circle{
	double r;
	point h;
}ans;
int n;
double dis(point a,point b){
	return sqrt(pow((a.x-b.x),2)+pow(a.y-b.y,2));
}
point Mid(point a,point b){
	return {(a.x+b.x)/2,(a.y+b.y)/2};
}
circle Tcircle(point a,point b,point c){
	double x1=a.x,x2=b.x,x3=c.x;
	double y1=a.y,y2=b.y,y3=c.y;
	double A=x1*x1+y1*y1,B=x2*x2+y2*y2,C=x3*x3+y3*y3;
	double u1=x1-x2,u2=x1-x3,u3=x2-x3;
	double v1=y1-y2,v2=y1-y3,v3=y2-y3;
	point h;
	h.x=((C-A)*v1-(B-A)*v2)/(2*u1*v2-2*u2*v1);
	h.y=((C-A)*u1-(B-A)*u2)/(2*v1*u2-2*v2*u1);
	return {dis(h,c),h};
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>p[i].x>>p[i].y;
	ans.r=0;
	ans.h={p[1].x,p[1].y};
	for(int i=2;i<=n;++i)
		if(dis(p[i],ans.h)>ans.r){
			ans={0,p[i]};
			for(int j=1;j<i;++j)
				if(dis(p[j],ans.h)>ans.r){
					ans={dis(p[j],p[i])/2,Mid(p[j],p[i])};
					for(int k=1;k<j;++k)
						if(dis(p[k],ans.h)>ans.r)
							ans=Tcircle(p[i],p[j],p[k]);
				}
		}
	printf("%.10lf\n%.10lf %.10lf",ans.r,ans.h.x,ans.h.y);
	return 0;	
}

Tcircle函数是学习的这篇题解

2024/12/16 11:05
加载中...