fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int n;
  5. long double x[15000],y[15000];
  6. long double f(long double k){
  7. long double rez=0;
  8. for (int i=0;i<n;i++)
  9. rez=rez+sqrt(y[i]*y[i]+(x[i]-k)*(x[i]-k));
  10. return rez;
  11. }
  12. int main(){
  13. freopen("input.txt","r",stdin);
  14. freopen("output.txt","w",stdout);
  15. long double l,r;
  16. cin>>n;
  17. for (int i=0;i<n;i++)
  18. cin>>x[i]>>y[i];
  19. l=x[0];
  20. r=x[1];
  21. for (int i=0;i<500;i++)
  22. {
  23. long double k=(r-l)/3;
  24. if (f(l+k)>f(l+k+k))
  25. l=l+k;
  26. else r=l+k*2;
  27. }
  28. cout<<r;
  29. return 0;
  30. }
Success #stdin #stdout 0s 3644KB
stdin
Standard input is empty
stdout
Standard output is empty