Alice is interesting in computation geometry problem recently. She found a interesting problem and solved it easily. Now she will give this problem to you
You are given N distinct points (Xi,Yi) on the two-dimensional plane. Your task is to find a point P and a real number R, such that for at least ⌈N/2⌉ given points, their distance to point P is equal to R.
N<=1e5
题意: 给你N个点,求出某个圆上至少有一半的点在上面
思路: 因为题面已经保证至少有一半点在某个圆上,我们可以随机取三个点,至少有1/8的概率同时取到三个点就是那一半的点,而三点可以确定一个圆,故一般来说大概8次有1次可以找到那个圆,注意需要注意点数小于4的时候特判掉就行
三点确定一个圆的公式与模板,记得需要限制条件保证三点不在一条直线上

已知三点求圆心与半径模板
double dis2(int a)
{
return sqrt((p[a].x-x)*(p[a].x-x)+(p[a].y-y)*(p[a].y-y));
}
void cal(int a,int b,int c)//求外心
{
double a1 = p[b].x - p[a].x, b1 = p[b].y - p[a].y, c1 = (a1*a1 + b1*b1)/2;
double a2 = p[c].x - p[a].x, b2 = p[c].y - p[a].y, c2 = (a2*a2 + b2*b2)/2;
double d = a1 * b2 - a2 * b1;
寻找满足条件的圆:基础计算几何与随机化解法

该问题描述了一个计算几何的挑战,要求找出一个点P和半径R,使得至少有一半给定的平面上不重复的点到点P的距离等于R。当N小于4时需要特殊处理,通常通过随机选取三个点来确定一个圆,这种方法有约1/8的概率找到正确解,大约尝试8次即可找到满足条件的圆。
最低0.47元/天 解锁文章
291

被折叠的 条评论
为什么被折叠?



