思路

  三分模板题,由于模拟退火太久没看不会调参只水了一半的分只好过来打正解了。。

 

 CODE

 

  1 #include <bits/stdc++.h>
  2 #define dbg(x) cout << #x << "=" << x << endl
  3 #define eps 1e-8
  4 
  5 using namespace std;
  6 typedef long long LL;
  7 
  8 template<class T>inline void read(T &res)
  9 {
 10     char c;T flag=1;
 11     while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
 12     while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
 13 }
 14 
 15 namespace _buff {
 16     const size_t BUFF = 1 << 19;
 17     char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
 18     char getc() {
 19         if (ib == ie) {
 20             ib = ibuf;
 21             ie = ibuf + fread(ibuf, 1, BUFF, stdin);
 22         }
 23         return ib == ie ? -1 : *ib++;
 24     }
 25 }
 26 
 27 int qread() {
 28     using namespace _buff;
 29     int ret = 0;
 30     bool pos = true;
 31     char c = getc();
 32     for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
 33         assert(~c);
 34     }
 35     if (c == '-') {
 36         pos = false;
 37         c = getc();
 38     }
 39     for (; c >= '0' && c <= '9'; c = getc()) {
 40         ret = (ret << 3) + (ret << 1) + (c ^ 48);
 41     }
 42     return pos ? ret : -ret;
 43 }
 44 
 45 const int maxn = 1e5 + 7;
 46 
 47 int n;
 48 double l,r;
 49 
 50 struct node {
 51     double x, y;
 52 }a[maxn];
 53 
 54 double dis(double x, int i) {
 55     return sqrt((a[i].y*a[i].y)+(a[i].x-x)*(a[i].x-x));
 56 }
 57 
 58 double Max(double a, double b) {
 59     if(b - a > eps) {
 60         return b;
 61     }
 62     return a;
 63 }
 64 
 65 double f(double x) {
 66     double u = 1, p = -1e8;
 67     for(int i = 1; i <= n; ++i) {
 68         p = Max(p,(a[i].y*a[i].y)+(a[i].x-x)*(a[i].x-x));
 69     }
 70     return sqrt(p);
 71 }
 72 
 73 double ts(double l, double r) {
 74     while(r >= l + eps) {
 75         //dbg(l),dbg(r);
 76         double lmid = l + (r-l)/3, rmid = r - (r-l)/3;
 77         if(f(lmid) <= f(rmid)) {
 78             r = rmid;
 79         }
 80         else {
 81             l = lmid;
 82         }
 83     }
 84     //dbg(l);
 85     return l;
 86 }
 87 
 88 int main()
 89 {
 90     memset(a, 0, sizeof(a));
 91     scanf("%d",&n);
 92 
 93     for(int i = 1; i <= n; ++i) {
 94         scanf("%lf %lf",&a[i].x, &a[i].y);
 95     }
 96     double mid = ts(-10000,10000);
 97     double ans = f(mid);
 98     printf("%.8lf\n",ans);
 99     return 0;
100 }
View Code