Artifact Content
Not logged in

Artifact 29731d8057f689930323f9f653f055a3d4f1d985


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

double f(int a, int n)
{
	double x = 1;
	while( n --> 0 )
		x *= a--;
	return x;
}
double f(int a)
{
	return f(a, a);
}
double C(int n, int k)
{
	return f(n,k) / f(k,k);
}

class Flush
{
public:
	double size(vector <int> suits, int number) 
	{
		double all = f(accumulate(suits.begin(), suits.end(), 0), number);

		double ans = 0;
		for(int i1=0; i1<=number && i1<=suits[0]; ++i1)
		for(int i2=0; i1+i2<=number && i2<=suits[1]; ++i2)
		for(int i3=0; i1+i2+i3<=number && i3<=suits[2]; ++i3)
		{
			int i4 = number - i1 - i2 - i3;
			if( i4 <= suits[3] ) {
				double nf = max(max(i1,i2),max(i3,i4));
				double n = C(number, i1) * C(number-i1, i2) * C(number-i1-i2, i3)
					* f(suits[0],i1) * f(suits[1],i2) * f(suits[2],i3) * f(suits[3],i4);
				ans += nf * n/all;
			}
		}
		return ans;
	}
};

// 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> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const double &Expected, const double &Received) { double diff = Expected - Received; if (diff < 0) diff = -diff; if (diff < 1e-9) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } return 0;}

template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
	int suits_[] = {2,2,2,2};
	  vector <int> suits(suits_, suits_+sizeof(suits_)/sizeof(*suits_)); 
	int number = 2; 
	double RetVal = 1.1428571428571428; 
	return verify_case(RetVal, Flush().size(suits, number)); }
int Test_(Case_<1>) {
	int suits_[] = {1,4,7,10};
	  vector <int> suits(suits_, suits_+sizeof(suits_)/sizeof(*suits_)); 
	int number = 22; 
	double RetVal = 10.0; 
	return verify_case(RetVal, Flush().size(suits, number)); }
int Test_(Case_<2>) {
	int suits_[] = {13, 13, 13, 13};
	  vector <int> suits(suits_, suits_+sizeof(suits_)/sizeof(*suits_)); 
	int number = 49; 
	double RetVal = 13.0; 
	return verify_case(RetVal, Flush().size(suits, number)); }
int Test_(Case_<3>) {
	int suits_[] = {13, 13, 13, 13};
	  vector <int> suits(suits_, suits_+sizeof(suits_)/sizeof(*suits_)); 
	int number = 26; 
	double RetVal = 8.351195960938014; 
	return verify_case(RetVal, Flush().size(suits, number)); }
int Test_(Case_<4>) {
	int suits_[] = {13,13,13,13};
	  vector <int> suits(suits_, suits_+sizeof(suits_)/sizeof(*suits_)); 
	int number = 0; 
	double RetVal = 0.0; 
	return verify_case(RetVal, Flush().size(suits, number)); }

template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<>      void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE