当前位置:网站首页>Minimum circle coverage (basis of computational geometry)
Minimum circle coverage (basis of computational geometry)
2022-04-22 07:30:00 【S atur】


Ideas :
① randomization Point set ( Reduces complexity )
② Initially, find two points at random , Set to
and
, With
and
Make an initial circle for the diameter
( With Indicates before overwriting i The smallest circle of a point ).
③ Add new points in turn
, If the current point
In the circle
in , be
, Otherwise, we should
Make a circle as the end point of the new diameter ( Obviously
On the boundary of the new circle ).
④ But the new round It doesn't necessarily include all the previous i A little bit , So we went through the search and found i One point is not in
In the point
, So a little
and
It must be on the boundary of the new circle , So directly
Make a new circle for the diameter
.
⑤ Again
It doesn't necessarily include all the previous j A little bit , So find another point
, Be sure
,
,
On the boundary of the new circle , Then we can find this Circumscribed circle of three points That is, get a new circle
.
⑥ The circle obtained by these three cycles is called coverage At present The smallest circle of all points .
⑦ I don't know why randomization reduces complexity , Here's the big guy's proof :

For other specific ideas and proofs, see other Big blog .
Code implementation :
#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9+7;
const int N = 2e5 + 5;
inline void read(int &x){
char t=getchar();
while(!isdigit(t)) t=getchar();
for(x=t^48,t=getchar();isdigit(t);t=getchar()) x=x*10+(t^48);
}
int n;
double r;
struct node{
double x, y;
}o, a[N];
double dis(node a, node b){ // Get the distance between two points
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void get(node a, node b, node c){ // Three points determine a circle
double x1 = a.x-b.x, y1 = a.y-b.y;
double d1 = (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)/2;
double x2 = a.x-c.x, y2 = a.y-c.y;
double d2 = (a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)/2;
o.x = (d1*y2-y1*d2)/(x1*y2-y1*x2);
o.y = (d2*x1-x2*d1)/(x1*y2-y1*x2);
r = dis(o, a);
}
signed main()
{
IOS;
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> a[i].x >> a[i].y;
random_shuffle(a+1, a+n+1);
o = a[1]; // Take the first point as the center of the circle
for(int i = 2; i <= n; i ++){
if(dis(o, a[i])>r+eps){ // Find the first point not in the circle
o = {(a[1].x+a[i].x)/2, (a[1].y+a[i].y)/2}; // Update center point
r = dis(o, a[i]); // Update radius
for(int j = 1; j < i; j ++){
if(dis(o, a[j])>r+eps){ // Find the second point not in the circle
o = {(a[i].x+a[j].x)/2, (a[i].y+a[j].y)/2}; // Update center point
r = dis(o, a[j]); // Update radius
for(int k = 1; k <j; k ++){
if(dis(o, a[k])>r+eps){ // Find the third point that is not in the circle
get(a[i], a[j], a[k]); // Three points outside the circle to update the smallest circle
}
}
}
}
}
}
printf("%.10f\n%.10f %.10f\n", r, o.x, o.y);
return 0;
}
版权声明
本文为[S atur]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220616061299.html
边栏推荐
- CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes)
- P1095 [noip2007 popularity group] escape of the catcher
- Leetcode - 6 - (chaîne multiplicatrice, prochain élément plus grand < Ⅰ Ⅱ Ⅲ >, K liste de chaînes inversées)
- 并发编程的艺术(9):final的使用和原理
- Leetcode - 7 - (nearest common ancestor of binary tree, rotation array, direct of binary tree, next permutation, combined sum)
- 1232. Minimum number of arrows for exploding balloons
- pip一直更新失败?多数是网络问题!
- 15. Full arrangement
- 并发编程的艺术(6):详解ReentrantLock的原理
- A.Binary Seating (概率) (2021年度训练联盟热身训练赛第五场)
猜你喜欢

This关键字详细概述

A. Alice and Bob (game? Thinking & Violence) (2021 Niuke summer multi school training camp 1)

C.Ducky Debugging(简单判断/签到)(2021年度训练联盟热身训练赛第五场 )

A. Weird Flecks, But OK (计算几何&三维最小圆覆盖)(2021年度训练联盟热身训练赛第一场)

系统日志文件过大优化
![P1095 [NOIP2007 普及组] 守望者的逃离](/img/5e/0437bdee83b6b66626e535e382b84b.png)
P1095 [NOIP2007 普及组] 守望者的逃离

D. Determine the photo position (simply find the substring) (2021 Niuke summer multi school training camp 1)

Internal class instructions (static, instance, local)

Vivado generates and invokes EDF netlist files

Abstract classes and abstract methods
随机推荐
15. Full arrangement
Codeforces Round #776 (Div. 3)
Codeforces Round #774 (Div. 2)
Unknown graphics extension:. 1 jpg. }
Codeforces Round #778
332 · 恢复数组
1232 · 爆破气球的最小箭头数
要是我再犯这种憨憨错误就.../(ㄒoㄒ)/~~
189. 轮转数组
Cannot find interface mapping after updating HDF
D. Determine the Photo Position (简单找子串)(2021牛客暑期多校训练营1)
Codeforces Round #779 (Div. 2)
LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)
Host cannot Ping virtual machine in bridging mode
The art of concurrent programming (11): introduction to tool classes in JUC
Yapi的安装与配置(转载)
L2-005 集合相似度(set判重)
Codeforces Round #634 (Div. 3)
Codeforces Round #778
C. Ducky debugging (Game 5 of 2021 training League warm-up training competition)