当前位置:网站首页>A. Weird flecks, but OK (Computational Geometry & three-dimensional minimum circle coverage) (the first game of 2021 Training Alliance warm-up training competition)
A. Weird flecks, but OK (Computational Geometry & three-dimensional minimum circle coverage) (the first game of 2021 Training Alliance warm-up training competition)
2022-04-22 07:29:00 【S atur】





The question : There are... In a three-dimensional cube n A flaw , Now I hope to cut a circle vertically downward from a plane to remove all defects , You need to find the smallest circle diameter that can remove all points at one time , That is to find... In three dimensions Minimum circle cover .
Ideas : One more dimension than the conventional minimum circle coverage , It can be solved in three directions for three times, and the minimum answer can be taken .
Code implementation 1:
#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-12;
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 a[N][5], r, ox, oy;
double dis(double ax, double ay, double bx, double by){
return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
}
void get(double ax, double ay, double bx, double by, double cx, double cy){
double x1 = ax-bx, y1 = ay-by;
double d1 = (ax*ax-bx*bx+ay*ay-by*by)/2;
double x2 = ax-cx, y2 = ay-cy;
double d2 = (ax*ax-cx*cx+ay*ay-cy*cy)/2;
ox = (d1*y2-y1*d2)/(x1*y2-y1*x2);
oy = (d2*x1-x2*d1)/(x1*y2-y1*x2);
r = dis(ox, oy, ax, ay);
}
double solve(int u, int v){
ox = a[1][u], oy = a[1][v], r = 0;
for(int i = 2; i <= n; i ++){
if(dis(ox, oy, a[i][u], a[i][v])>r+eps){
ox = a[i][u], oy = a[i][v], r = 0;
for(int j = 1; j < i; j ++){
if(dis(ox, oy, a[j][u], a[j][v])>r+eps){
ox = (a[i][u]+a[j][u])/2;
oy = (a[i][v]+a[j][v])/2;
r = dis(ox, oy, a[j][u], a[j][v]);
for(int k = 1; k < j; k ++){
if(dis(ox, oy, a[k][u], a[k][v])>r+eps){
get(a[i][u], a[i][v], a[j][u], a[j][v], a[k][u], a[k][v]);
}
}
}
}
}
}
return r*2;
}
signed main()
{
// IOS;
cin >> n;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= 3; j ++){
cin >> a[i][j];
}
}
random_shuffle(a+1, a+n+1);
double ans = min(solve(1, 2), min(solve(1, 3), solve(2, 3)));
printf("%.10f\n", ans);
return 0;
}
Code implementation 2:( The method is not well understood )
#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-8;
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 a[N][5];
double solve(int u, int v)
{
// Initialize the answer and error value , The error value here needs special consideration , If the size is not enough, you may not have found the correct answer
double res = inf, delta = 100;
double x = 0, y = 0; //x,y That is, the coordinates of the center of the circle
while(delta>eps){
int k = 0; double d = 0;
for(int i = 1; i <= n; i ++){
//hypot() Calculate the hypotenuse length of a right triangle , amount to sqrt(x*x, y*y)
double dis = hypot(a[i][u]-x, a[i][v]-y);
if(dis>d){
d = dis;
k = i;
}
}
res = min(res, d);
x += (a[k][u]-x)/d*delta;
y += (a[k][v]-y)/d*delta;
delta *= 0.99;
}
return res*2;
}
signed main()
{
// IOS;
cin >> n;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= 3; j ++){
cin >> a[i][j];
}
}
// Find the minimum covering circle from three plane dimensions
double ans = min(solve(1, 2), min(solve(1, 3), solve(2, 3)));
printf("%.10f\n", ans);
return 0;
}
版权声明
本文为[S atur]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220616061258.html
边栏推荐
猜你喜欢

1005 Monopoly 同余求解(2021中国大学生程序设计竞赛CCPC-网络选拔赛重赛)

Leetcode - 6 - (chaîne multiplicatrice, prochain élément plus grand < Ⅰ Ⅱ Ⅲ >, K liste de chaînes inversées)

B. Ball Dropping (简单几何计算 / 相似三角形) (2021牛客暑期多校训练营1)

并发编程的艺术(6):详解ReentrantLock的原理
![P1095 [NOIP2007 普及组] 守望者的逃离](/img/5e/0437bdee83b6b66626e535e382b84b.png)
P1095 [NOIP2007 普及组] 守望者的逃离

Leetcode - 4 - (longest substring without repeated characters, candy distribution, binary tree traversal)

Abstract classes and abstract methods

Definition and difference between rewriting and overloading

E. Figure skiing (string sorting / check-in) (Game 5 of 2021 training League warm-up training competition)

H.Happy Number (进制转换/第n个特殊数)(2021牛客暑期多校训练营9 )
随机推荐
Detailed overview of this keyword
P1095 [noip2007 popularity group] escape of the catcher
The system log file is too large
The art of concurrent programming (11): introduction to tool classes in JUC
If I make this silly mistake again/ (ㄒoㄒ)/~~
A. Alice and Bob (博弈?思维&暴力)(2021牛客暑期多校训练营1)
Art de la programmation simultanée (9): utilisation finale et principes
LeetCode - 8 - (三数之和、Z字形变换、两数之和<链表>、盛最多水的容器、电话号码的字母组合)
H. Happy number (binary conversion / nth special number) (2021 Niuke summer multi school training camp 9)
LeetCode - 1 - (树的子结构、组合、螺旋矩阵、全排列<ⅠⅢ>)
15 · 全排列
Can the following SQL optimize query performance with index
278 · 绘制填充
Vivado generates and invokes EDF netlist files
instanceof的使用说明及实例讲解
Definition and difference between rewriting and overloading
Redis Advanced
I.Jam-packed (均分/最大最小值) (2021年度训练联盟热身训练赛第五场)
332 · 恢复数组
363 · 接雨水