fork(1) download
  1. #include<bits/stdc++.h>
  2. #define MOD 1000000007
  3. #define EPS 1e-9
  4. #define ll long long
  5. #define ld long double
  6. #define pb push_back
  7. #define mp make_pair
  8. #define endl '\n'
  9. #define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
  10. const ld PI=3.141592653589793238L;
  11. const ll N=300002;
  12. using namespace std;
  13.  
  14.  
  15. ld solve(vector<ld>&v){
  16. ld elly=v[0];
  17. sort(v.rbegin(),v.rend());
  18.  
  19. ld r = ceil((ld)v.size()/20);
  20.  
  21. ld sum=0; // this will contain the answer.
  22. ld curr=0;
  23. ld n=0;
  24. bool last=0;
  25. while(curr < v.size()){
  26. vector<ld>tmp;
  27. ++n;
  28. bool found=0;
  29. for(int i=curr;i<min((ld)v.size(),curr+r);++i) found=(v[i]==elly) , tmp.pb(v[i]);
  30.  
  31. curr += r;
  32.  
  33. if(found) sum+=elly; // this group contains elly's rating
  34. else if(curr < v.size()) foreach(it,tmp) sum+=(ld)*it/r; // this isn't the last group
  35. else{
  36. last=1;
  37. ld sum1=sum; foreach(it,tmp) sum1+=(ld)*it/tmp.size();
  38. ld sum2=sum;
  39.  
  40. ld p = (ld)tmp.size()/r , q = 1-p;
  41.  
  42. sum1*=p , sum2*=q;
  43.  
  44. sum = sum1/n + sum2/(n-1);
  45. }
  46. }
  47.  
  48. if(!last) sum /= n; // the last group contained elly's rating so we never entered the "else" section.
  49.  
  50. return sum;
  51. }
  52.  
  53. class EllysRoomAssignmentsDiv1{
  54. public: double getAverage(vector <string> ratings){
  55. string s="";
  56. foreach(it,ratings) s+=*it;
  57.  
  58. vector<ld>v;
  59. istringstream iss(s);
  60. ld x;
  61. while(iss >> x) v.pb(x);
  62.  
  63. return solve(v);
  64. };
  65. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty