fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. #define forn(i, n) for (int i = 0; i < int(n); i++)
  6.  
  7.  
  8. long double getWinProbability(long double ra, long double rb) {
  9. return 1.0 / (1.0 + pow((long double) 10.0, (rb - ra) / 400.0));
  10. }
  11. long double aggregateRatings(vector<long double> teamRatings)
  12. {
  13. long double left = 1;
  14. long double right = 1E4;
  15.  
  16. for (int tt = 0; tt < 100; tt++) {
  17. long double r = (left + right) / 2.0;
  18.  
  19. long double rWinsProbability = 1.0;
  20. forn(i, teamRatings.size())
  21. rWinsProbability *= getWinProbability(r, teamRatings[i]);
  22.  
  23. long double rating = log10(1 / (rWinsProbability) - 1) * 400 + r;
  24.  
  25. if (rating > r)
  26. left = r;
  27. else
  28. right = r;
  29. }
  30.  
  31. return (left + right) / 2.0;
  32. }
  33.  
  34. int main() {
  35. vector<long double> teamRating = {2589, 2115, 2411, 2336, 2142, 1939, 2691,
  36. 2411, 1794, 2123, 2226, 2185, 2106, 2297, 1862, 2164, 2190, 1961,
  37. 2753, 2730, 2599, 2516, 3129};
  38. cout << aggregateRatings(teamRating);
  39. }
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
3237.32