A - Trick or Treat Gym - 102470A(三分)

    科技2022-07-13  114

    题意: 一堆点在x轴上某个点会和,要你找到一个x轴上的点使得会和时间最短。

    思路: 三分这个点即可

    #pragma GCC optimize(3,"Ofast","inline") #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef double db; bool Finish_read; template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;} template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');} template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');} template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);} #define all(x) (x).begin(), (x).end() #define clr(a, b) memset((a), (b), sizeof((a))) #define rep(i,s,t) for(register int i=s;i<t;++i) #define per(i,s,t) for(register int i=s;i>=t;--i) #define iis std::ios::sync_with_stdio(false);cin.tie(0) #define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end()) // mt19937 rng(time(NULL)); // mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 generator(std::clock()); // shuffle(arr, arr + n, generator); /*================Header Template==============*/ const int maxn = 1e5 + 7; struct Node { double x,y; }a[maxn],b[maxn]; int n; double dis(Node a,Node b) { return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double f(double mid) { double ans = 0.0; Node p = {mid,0.0}; for(int i = 1;i <= n;i++){ double d = dis(a[i],p); ans = max(ans,d); } return ans; } int main(){ while(~scanf("%d",&n) && n){ double l = 200000,r = -200000; for(int i = 1;i <= n;i++){ scanf("%lf%lf",&a[i].x,&a[i].y); l = min(l,a[i].x); r = max(r,a[i].x); } for(int i = 1;i <= 54;i++) { double mid1 = l + (r - l) / 3, mid2 = l + (r - l) / 3 * 2; if(f(mid1) > f(mid2)) { l = mid1; } else { r = mid2; } } printf("%.6f %.6f\n",l,sqrt(f(l))); } return 0; }
    Processed: 0.015, SQL: 8