expectedBounces
日課消化。いつもこういう綺麗な解法が見つかればいいんですけどね。
#include <algorithm> #include <iostream> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define FOR(i,s,e) for (int i = int(s); i != int(e); i++) #define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ISEQ(c) (c).begin(), (c).end() class BouncingBalls { public: double expectedBounces(vector<int> x, int T) { sort(x.begin(), x.end()); double result = 0; for(unsigned int i=0; i<x.size()-1; i++){ for(unsigned int j=i+1; j<x.size(); j++){ if(x[j] - x[i] <= 2*T) result++; } } return (result / 4.0); } };