fork download
  1. //#Ewise Electric
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long
  6. bool ONE_CASE=true;
  7.  
  8. const ll OL=1e18;
  9. const double eps=1e-7;
  10. vector<pair<long double,long double>> neods;
  11. int n;
  12.  
  13. void solve(){
  14. cin>>n;
  15.  
  16. for(int i=0;i<n;i++){
  17. int l,m;
  18. cin>>l>>m;
  19. neods.push_back({l,m});
  20. }
  21. sort(neods.begin(),neods.end());
  22. cout<<fixed<<setprecision(8);
  23.  
  24. for(int i=0;i<n-1;i++){
  25.  
  26. //we need to BS between l and r
  27. long double l=neods[i].first,r=neods[i+1].first;
  28. long double mid=(l+r)/2.0,x1=0,x2=0;
  29. for(int z=i+1;z<n;z++){
  30. x2+=(neods[z].second)/(powl((neods[z].first-mid),2));
  31. }
  32. for(int z=0;z<=i;z++){
  33. x1+=(neods[z].second)/(powl((neods[z].first-mid),2));
  34. if(x1>x2+eps)break;
  35. }
  36. while(abs(x2-x1)>eps){
  37.  
  38.  
  39. /*cout<<mid<<endl;
  40.   cout<<x2<<"#"<<x1<<endl;*/
  41.  
  42. if(x2>x1){
  43. r=mid;
  44. }
  45. else{
  46. l=mid;
  47. }
  48. mid=(r+l)/2.0;
  49. x1=x2=0;
  50. for(int z=i+1;z<n;z++){
  51. x2+=(neods[z].second)/(powl((neods[z].first-mid),2));
  52. }
  53. for(int z=0;z<=i;z++){
  54. x1+=(neods[z].second)/(powl((neods[z].first-mid),2));
  55. if(x1>x2+eps)break;
  56. }
  57. /*cout<<mid<<endl;
  58.   cout<<x2<<"#"<<x1<<endl;*/
  59. }
  60.  
  61. cout<<mid<<endl;
  62. }
  63. }
  64. int main(){
  65. ios_base::sync_with_stdio(false);
  66. cin.tie(NULL);
  67.  
  68.  
  69.  
  70. int t=1;
  71. if(!ONE_CASE)
  72. cin>>t;
  73. while(t--){
  74.  
  75. solve();
  76. }
  77. }
Success #stdin #stdout 0.01s 5420KB
stdin
Standard input is empty
stdout
Standard output is empty