zoukankan      html  css  js  c++  java
  • 2020牛客寒假算法基础集训营5 B.牛牛战队的比赛地 (二分/三分)

    https://ac.nowcoder.com/acm/contest/3006/B

    三分做法

     1 #include<bits/stdc++.h>
     2 #define inf 0x3f3f3f3f
     3 using namespace std;
     4 typedef long long ll;
     5 typedef pair<int,int> pll;
     6 const int maxn=1e5+10;
     7 const int mod =1e9+7;
     8 const double EPS = 1e-6;
     9 struct node
    10 {
    11     double x;
    12     double y;
    13 };
    14 node s[maxn];
    15 int n;
    16 double Calc(double num)
    17 {
    18     double ans=0;
    19     for(int i=1;i<=n;i++)
    20     {
    21         double q=sqrt((num-s[i].x)*(num-s[i].x)+s[i].y*s[i].y);
    22         if(q>ans)
    23         {
    24             ans=q;
    25         }
    26     }
    27     return ans;
    28 }
    29 int main()
    30 {
    31     cin >> n;
    32     int a,b;
    33     for(int i=1; i<=n; i++)
    34     {
    35         cin >> a >> b;
    36         s[i].x=a;
    37         s[i].y=b;
    38     }
    39     double Left, Right;
    40     double mid, midmid;
    41     double mid_value, midmid_value;
    42     Left = -10000;
    43     Right = 10000;
    44     while (Left + EPS < Right)
    45     {
    46         mid = (Left + Right)/2;
    47         midmid = (mid + Right)/2;
    48         mid_value = Calc(mid);
    49         midmid_value = Calc(midmid);
    50         if (mid_value <= midmid_value)
    51             Right = midmid;
    52         else
    53             Left = mid;
    54     }
    55     cout << Calc(Left) << endl;
    56     return 0;
    57 }
  • 相关阅读:
    test
    男神zyh的青睐
    HH的项链
    PAT刷题经验
    LaTeX常用数学符号
    Battle Over Cities Hard Version
    Cut
    文本生成器
    Explorer Space
    2021.04.21
  • 原文地址:https://www.cnblogs.com/AaronChang/p/12308543.html
Copyright © 2011-2022 走看看