zoukankan      html  css  js  c++  java
  • Problem D. Country Meow 2018ICPC南京

    n个点求出最小圆覆盖所有点

    退火算法不会,不过这题可以用三分套三分写

    x轴y轴z轴各三分 

     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 }
    View Code

     

  • 相关阅读:
    JDBC
    uml 和 unified process
    关于N9手机第三种交互方式的思考和再设计
    [jQuery插件] jQuery Color Animations颜色动画插件
    Azul发布开源工具jHiccup,为Java提供运行时响应时间分析
    行内元素verticalalign:middle在html5和xhtml1.0及以下版本中的表现差异
    使用maven进行scala项目的构建
    计划FM为人人网提供首个开源Ruby SDK
    Chrome扩展:Run Selected HTML
    Team Foundation Service更新:改善了导航和项目状态速查功能
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/9979586.html
Copyright © 2011-2022 走看看