n个点求出最小圆覆盖所有点
退火算法不会,不过这题可以用三分套三分写
x轴y轴z轴各三分
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 #include <algorithm> 6 #include <set> 7 #include <iostream> 8 #include <map> 9 #include <stack> 10 #include <string> 11 #include <vector> 12 #define pi acos(-1.0) 13 #define eps 1e-8 14 #define fi first 15 #define se second 16 #define rtl rt<<1 17 #define rtr rt<<1|1 18 #define bug printf("****** ") 19 #define mem(a,b) memset(a,b,sizeof(a)) 20 #define name2str(x) #x 21 #define fuck(x) cout<<#x" = "<<x<<endl 22 #define f(a) a*a 23 #define sf(n) scanf("%d", &n) 24 #define sff(a,b) scanf("%d %d", &a, &b) 25 #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c) 26 #define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d) 27 #define pf printf 28 #define FRE(i,a,b) for(i = a; i <= b; i++) 29 #define FREE(i,a,b) for(i = a; i >= b; i--) 30 #define FRL(i,a,b) for(i = a; i < b; i++)+ 31 #define FRLL(i,a,b) for(i = a; i > b; i--) 32 #define FIN freopen("data.txt","r",stdin) 33 #define gcd(a,b) __gcd(a,b) 34 #define lowbit(x) x&-x 35 using namespace std; 36 typedef long long LL; 37 typedef unsigned long long ULL; 38 const int mod = 1e9 + 7; 39 const int maxn = 2e5 + 10; 40 const int INF = 0x3f3f3f3f; 41 const LL INFLL = 0x3f3f3f3f3f3f3f3fLL; 42 int n; 43 struct node { 44 double p[3]; 45 } qu[maxn]; 46 double cal ( node a ) { 47 double cnt = 0; 48 for ( int i = 0 ; i < n ; i++ ) 49 cnt = max ( cnt, sqrt ( ( a.p[0] - qu[i].p[0] ) * ( a.p[0] - qu[i].p[0] ) + ( a.p[1] - qu[i].p[1] ) * ( a.p[1] - qu[i].p[1] ) + ( a.p[2] - qu[i].p[2] ) * ( a.p[2] - qu[i].p[2] ) ) ); 50 return cnt; 51 } 52 node check ( int cnt, node now ) { 53 if ( cnt >= 3 ) return now; 54 node ans1, ans2, ans, temp1, temp2; 55 double l = -100000, r = 100000, ll, rr; 56 ans = temp1 = temp2 = now; 57 while ( eps < r - l ) { 58 ll = ( 2 * l + r ) / 3, rr = ( 2 * r + l ) / 3; 59 temp1.p[cnt] = ll, temp2.p[cnt] = rr; 60 ans1 = check ( cnt + 1, temp1 ); 61 ans2 = check ( cnt + 1, temp2 ); 62 if ( cal ( ans1 ) > cal ( ans2 ) ) ans = ans1, l = ll; 63 else r = rr, ans = ans2; 64 } 65 return ans; 66 } 67 int main() { 68 while ( ~sf ( n ) ) { 69 for ( int i = 0 ; i < n ; i++ ) scanf ( "%lf%lf%lf", &qu[i].p[0], &qu[i].p[1], &qu[i].p[2] ); 70 node ans; 71 printf ( "%lf ", cal ( check ( 0, ans ) ) ); 72 } 73 return 0; 74 }