Facebook
From Innocent Porcupine, 4 Years ago, written in Plain Text.
This paste is a reply to Untitled from Queen Lion - view diff
Embed
Download Paste or View Raw
Hits: 203
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MAX 1000003
  4. #define tiny 0.000000001
  5. #define pi acos(-1)
  6. int N,F;
  7. int r[MAX];
  8. bool check(double x){
  9.         double np=0;//number of person
  10.         for(int i=1;i<=N;i++){
  11.                 np+= double (r[i]*r[i]/x);
  12.         }
  13.         if(np >= (F+1)) return true;
  14.         else return false;
  15. }
  16. int main(){
  17.         ios::sync_with_stdio(0);
  18.         cin.tie(0);
  19.         int n;
  20.         cin>>n;
  21.         double upper=MAX*10,lower=tiny;
  22.         double x;
  23.         while(n--){
  24.                 cin>>N>>F;
  25.                 for(int i=1;i<=N;i++) cin>>r[i];
  26.                 //mergeSort(r,1,N);
  27.                 while(upper - lower > tiny){
  28.                         x=double((upper+lower)/2);
  29.                         if(check(x)) lower=x;
  30.                         else upper=x;
  31.                 }
  32.                 cout<<fixed<<setprecision(6)<<pi*upper<<endl;
  33.         }
  34. }