Algorithm
Problem Statement for BouncingBalls Problem link- https://community.topcoder.com/stat?c=problem_statement&pm=10726&rd=14180&rm=&cr=14970299 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
class BouncingBalls {
public:
double expectedBounces(vector<int> x, int T) {
sort(x.begin(), x.end());
double res = 0;
for(int i = 0; i < x.size(); ++i)
for(int j = i + 1; j < x.size(); ++j)
if(abs(x[i] - x[j]) <= 2 * T)
res += 0.25;
return res;
}
};
Copy The Code &
Try With Live Editor
Input
{5, 8}
2
2
Output
0.25
Demonstration
TopCoder Solution SRM458-D2-500 Statement for BouncingBalls C,C++, Java, Js and Python ,SRM458-D2-500,TopCoder Solution