Advertisement
Diene

Untitled

Jan 24th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector <int> pies;
  6.  
  7. double binarysearch( double l, double r, int f){
  8.     int soma=0;
  9.     double mid=(l+r)/2;
  10.     for(int i=0; i<pies.size(); i++){
  11.         soma+=pies[i]/mid;
  12.     }
  13.     if(abs(r-l)<0.00001) return mid;
  14.     if(soma >= f+1) return binarysearch(mid, r, f);
  15.     return binarysearch(l,mid,f);
  16. }
  17.  
  18. int main(){
  19.  
  20.     int t, n,f,aux;
  21.     cin>>t;
  22.  
  23.     for(int i=0;i<t;i++){
  24.         int ma=0;
  25.         cin>>n>>f;
  26.         for(int j=0;j<n;j++){
  27.             cin>>aux;
  28.             pies.push_back(aux*aux);
  29.             ma=max(ma,aux*aux);
  30.         }
  31.         printf("%.4f\n", binarysearch(0,ma,f)*M_PI);
  32.         pies.clear();
  33.     }
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement