Artifact Content
Not logged in

Artifact 7de7b5143ca315629eb85bf132da22a677860227


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class TheBoredomDivOne { public:
	double find(int n, int m) 
	{
		double total = (n+m)*(n+m-1);

		vector<double> e(n+m+1);
		e[n+m] = 0;
		for(int i=n+m-1; i>=n; --i)
		{
			double p2 = (n+m-i)*(n+m-i-1) / total;
			double p1 = 2*i*(n+m-i) / total;
			double p0 = 1-p2-p1;

			// e[i] = 1 + p0*e[i] + p1*e[i+1] + p2*e[i+2];
			e[i] = 1/(1-p0) + p1/(1-p0)*e[i+1] + (i==n+m-1 ? 0 : p2/(1-p0)*e[i+2]);
		}
		return e[n];
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const double& Expected, const double& Received) {
 bool ok = (abs(Expected - Received) < 1e-9);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TheBoredomDivOne().find(n, m));}
int main(){

CASE(0)
	int n = 1; 
	int m = 1; 
	double _ = 1.0; 
END
CASE(1)
	int n = 2; 
	int m = 1; 
	double _ = 1.5; 
END
CASE(2)
	int n = 1; 
	int m = 2; 
	double _ = 2.0; 
END
CASE(3)
	int n = 4; 
	int m = 7; 
	double _ = 13.831068977298521; 
END
	/*
CASE(4)
	int n = ; 
	int m = ; 
	double _ = ; 
END
CASE(5)
	int n = ; 
	int m = ; 
	double _ = ; 
END
*/
}
// END CUT HERE