fork download
  1. #define _GLIBCXX_FILESYSTEM
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define ll long long
  6.  
  7.  
  8. double pos[100001];
  9. double v[100001];
  10.  
  11. int n;
  12.  
  13. double calc(double x)
  14. {
  15.  
  16. double t=-1e17;
  17. for(int i=0;i<n;i++)
  18. {
  19. t=max(t,abs(pos[i]-x)/v[i]);
  20.  
  21. }
  22. return t;
  23. }
  24.  
  25. int main()
  26. {
  27.  
  28. IOS
  29. cin>>n;
  30. double mx=INT_MIN;
  31. for(int i=0;i<n;i++)
  32. {
  33. cin>>pos[i]>>v[i];
  34. mx=max(mx,pos[i]);
  35. }
  36.  
  37. double l=-mx-20;
  38. double r=mx+20;
  39.  
  40. if(n==1)
  41. {
  42. cout<<0<<"\n";
  43. return 0;
  44. }
  45. for(int i=0;i<300;i++)
  46. {
  47.  
  48. double mid1=l+(r-l)/3.0;
  49. double mid2 = r - (r - l) / 3.0;
  50.  
  51. double m1=calc(mid1);
  52. double m2=calc(mid2);
  53.  
  54. if(m2<m1)
  55. l=mid1;
  56. else
  57. r=mid2;
  58. }
  59. cout<<fixed<<setprecision(10)<<calc(r)<<"\n";
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
Success #stdin #stdout 0s 5300KB
stdin
5
-1 5
10 3
4 2
7 10
8 1
stdout
1.5000000000