DELETED SRM/526.5-U/1B-U.cpp Index: SRM/526.5-U/1B-U.cpp ================================================================== --- SRM/526.5-U/1B-U.cpp +++ SRM/526.5-U/1B-U.cpp @@ -1,161 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __GNUC__ -#include -#define unordered_map __gnu_cxx::hash_map -#else -#include -#endif -using namespace std; -typedef long long LL; -typedef complex CMP; - -class MagicBlizzard { public: - double expectation(vector range, vector amount) - { - map ram; - for(int i=0; i > ra(ram.begin(), ram.end()); - int all = accumulate(amount.begin(), amount.end(), 0); - - double e = 0; - for(int i=0; i, double> memo; - double rec(vector< pair >& ra, int i, int snow_fall, int all) - { - if( i == ra.size() ) - return snow_fall == 0 ? 1.0 : 0.0; - if( all < snow_fall ) - return 0.0; - - pair key(i, snow_fall); - if( memo.count(key) ) - return memo[key]; - - LL r = ra[i].first; - int a = ra[i].second; - double p1 = double(1)/((2*r+1)*(2*r+1)); - double p0 = 1 - p1; - // (p0 #0 + p1 #1)^a - double csum = 0; - double Cak = 1; - for(int k=0; k<=min(a, snow_fall); ++k) - { - // coord of ^k - // C(a,k) p1^k p0^(a-k) - double c = Cak * pow(p1,k) * pow(p0,a-k); - csum += c * rec(ra, i+1, snow_fall-k, all-a); - - Cak = Cak * (a-k) / (k+1); - } - return memo[key] = csum; - } -}; - -// BEGIN CUT HERE -#include -double start_time; string timer() - { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } -template ostream& operator<<(ostream& os, const vector& v) - { os << "{ "; - for(typename vector::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(_, MagicBlizzard().expectation(range, amount));} -int main(){ - -CASE(0) - int range_[] = {1,0}; - vector range(range_, range_+sizeof(range_)/sizeof(*range_)); - int amount_[] = {1,1}; - vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); - double _ = 2.2222222222222223; -END -CASE(1) - int range_[] = {1,0}; - vector range(range_, range_+sizeof(range_)/sizeof(*range_)); - int amount_[] = {2,1}; - vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); - double _ = 3.666666666666667; -END -CASE(2) - int range_[] = {5,2,6,5}; - vector range(range_, range_+sizeof(range_)/sizeof(*range_)); - int amount_[] = {1,2,2,3}; - vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); - double _ = 8.46525111252384; -END -CASE(3) - int range_[] = {7,11,2,13,3,19,5,17}; - vector range(range_, range_+sizeof(range_)/sizeof(*range_)); - int amount_[] = {16,8,4,15,12,9,10,6}; - vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); - double _ = 98.55659436211914; -END -CASE(4) - int range_[] = {0,0,0,0,0,0,0,0,0,0}; - vector range(range_, range_+sizeof(range_)/sizeof(*range_)); - int amount_[] = {10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}; - vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); - double _ = 1.0E10; -END -CASE(5) - int range_[] = {1}; - vector range(range_, range_+sizeof(range_)/sizeof(*range_)); - int amount_[] = {100}; - vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); - double _ = 10000; -END -CASE(6) - int range_[] = { - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - }; - vector range(range_, range_+sizeof(range_)/sizeof(*range_)); - int amount_[] = { - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, - }; - vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); - double _ = -1; -END - -} -// END CUT HERE ADDED SRM/526.5-U/1B.cpp Index: SRM/526.5-U/1B.cpp ================================================================== --- SRM/526.5-U/1B.cpp +++ SRM/526.5-U/1B.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __GNUC__ +#include +#define unordered_map __gnu_cxx::hash_map +#else +#include +#endif +using namespace std; +typedef long long LL; +typedef complex CMP; + +class MagicBlizzard { public: + double expectation(vector range, vector amount) + { + vector< pair > ar; + for(int i=0; i +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::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(_, MagicBlizzard().expectation(range, amount));} +int main(){ + +CASE(0) + int range_[] = {1,0}; + vector range(range_, range_+sizeof(range_)/sizeof(*range_)); + int amount_[] = {1,1}; + vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); + double _ = 2.2222222222222223; +END +CASE(1) + int range_[] = {1,0}; + vector range(range_, range_+sizeof(range_)/sizeof(*range_)); + int amount_[] = {2,1}; + vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); + double _ = 3.666666666666667; +END +CASE(2) + int range_[] = {5,2,6,5}; + vector range(range_, range_+sizeof(range_)/sizeof(*range_)); + int amount_[] = {1,2,2,3}; + vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); + double _ = 8.46525111252384; +END +CASE(3) + int range_[] = {7,11,2,13,3,19,5,17}; + vector range(range_, range_+sizeof(range_)/sizeof(*range_)); + int amount_[] = {16,8,4,15,12,9,10,6}; + vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); + double _ = 98.55659436211914; +END +CASE(4) + int range_[] = {0,0,0,0,0,0,0,0,0,0}; + vector range(range_, range_+sizeof(range_)/sizeof(*range_)); + int amount_[] = {10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}; + vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); + double _ = 1.0E10; +END +/* +CASE(5) + int range_[] = ; + vector range(range_, range_+sizeof(range_)/sizeof(*range_)); + int amount_[] = ; + vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); + double _ = ; +END +CASE(6) + int range_[] = ; + vector range(range_, range_+sizeof(range_)/sizeof(*range_)); + int amount_[] = ; + vector amount(amount_, amount_+sizeof(amount_)/sizeof(*amount_)); + double _ = ; +END +*/ +} +// END CUT HERE