-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathBouncingBalls.cpp
49 lines (43 loc) · 1.06 KB
/
BouncingBalls.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
using namespace std;
class BouncingBalls {
public:
double expectedBounces(vector <int> x, int T) {
double ret = 0;
sort(x.begin(), x.end());
for (long long i=0; i<(1 << x.size()); i++) {
long long tmp = i;
for (int j=0; j<x.size(); j++) {
if ((tmp >> j) & 1) {
for (int k=j+1; k<x.size(); k++) {
if (!((tmp >> k) & 1)) {
// cout << tmp << endl;
if ((double)(x[k] - x[j]) / 2.0 <= (double)T) {
// cout << x[k] << " - " << x[j] << " / 2 = " << (x[k] - x[j]) / 2 << endl;
ret++;
}
}
}
}
}
}
ret /= (1 << x.size());
return ret;
}
};
// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor