Artifact 75565be9d11ad28a61bd4d51c821fea91aeede1a
#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class FixedDiceGameDiv1 { public:
double getExpectation(int a, int b, int c, int d)
{
if(a*b<=c*1)
return -1.0;
auto d1 = distr(a, b);
auto d2 = distr(c, d);
double total_prob = 0.0;
for(auto& vp: d1)
for(auto& zq: d2)
{
int v = vp.first;
double p = vp.second;
int z = zq.first;
double q = zq.second;
if(v > z)
total_prob += p*q;
}
double e = 0.0;
for(auto& vp: d1)
for(auto& zq: d2)
{
int v = vp.first;
double p = vp.second;
int z = zq.first;
double q = zq.second;
if(v > z)
e += v * p*q/total_prob;
}
return e;
}
map<int, double> distr(int n, int f)
{
if(n == 0) {
map<int, double> m;
m[0] = 1,0;
return m;
}
map<int, double> m = distr(n-1, f), m2;
for(auto& up: m) {
int u = up.first;
double p = up.second;
for(int v=1; v<=f; ++v)
m2[u+v] += p/f;
}
return m2;
}
};
// 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(_, FixedDiceGameDiv1().getExpectation(a, b, c, d));}
int main(){
CASE(0)
int a = 1;
int b = 2;
int c = 1;
int d = 5;
double _ = 2.0;
END
CASE(1)
int a = 3;
int b = 1;
int c = 1;
int d = 3;
double _ = 3.0;
END
CASE(2)
int a = 1;
int b = 5;
int c = 1;
int d = 1;
double _ = 3.4999999999999996;
END
CASE(3)
int a = 2;
int b = 6;
int c = 50;
int d = 30;
double _ = -1.0;
END
CASE(4)
int a = 50;
int b = 11;
int c = 50;
int d = 50;
double _ = 369.8865999182022;
END
/*
CASE(5)
int a = ;
int b = ;
int c = ;
int d = ;
double _ = ;
END
CASE(6)
int a = ;
int b = ;
int c = ;
int d = ;
double _ = ;
END
*/
}
// END CUT HERE