ADDED SRM/504.5/1A.cpp Index: SRM/504.5/1A.cpp ================================================================== --- SRM/504.5/1A.cpp +++ SRM/504.5/1A.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class TheNumbersWithLuckyLastDigit { public: + int find(int n) + { + int feasible[10][2] = { + {20, 5}, // 4+4+4+4+4 + {11, 2}, // 4+7 + {12, 3}, // 4+4+4 (4+4+7+7) + {23, 5}, // 4+4+4+4+7 + { 4, 1}, // 4 (7+7) + {15, 3}, // 4+4+7 + {16, 4}, // 4+4+4+4 + { 7, 1}, // 7 + { 8, 2}, // 4+4 (4+7+7) + {19, 4}, // 4+4+4+7 + }; + if( feasible[n%10][0] <= n ) + return feasible[n%10][1]; + return -1; + } +}; + +// 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 int& Expected, const int& Received) { + bool ok = (Expected == Received); + 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(_, TheNumbersWithLuckyLastDigit().find(n));} +int main(){ + +CASE(0) + int n = 99; + int _ = 4; +END +CASE(1) + int n = 11; + int _ = 2; +END +CASE(2) + int n = 13; + int _ = -1; +END +CASE(3) + int n = 1234567; + int _ = 1; +END +CASE(4) + int n = 1; + int _ = 2; +END +CASE(5) + int n = 1000000000; + int _ = -1; +END + +} +// END CUT HERE ADDED SRM/504.5/1B.java Index: SRM/504.5/1B.java ================================================================== --- SRM/504.5/1B.java +++ SRM/504.5/1B.java @@ -0,0 +1,50 @@ +import java.math.*; +import java.util.*; + +public class TheJackpotDivOne { + public long[] find(long[] money, long jackpot) + { + long M = 0; + for(int i=0; i0 ) { + Arrays.sort(money); + + BigInteger sum = BigInteger.ZERO; + for(int i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class TheTicketsDivOne { public: + double find(int n, int m) + { + vector p(1, 1.0); + for(int N=2; N<=n; ++N) { + vector q(N, 0.0); + + // q[0] = 1/6 + 1/2 q[N-1] + // q[i] = 1/2 q[i-1] + 1/3 p[i-1] + + double s = 1.0/6; + double f = 1.0/3; + for(int i=N-2; i>=0; --i) { + f = f/2; + s += f*p[i]; + } + q[0] = s / (1.0 - pow(0.5, N)); + for(int i=1; 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(_, TheTicketsDivOne().find(n, m));} +int main(){ + +CASE(0) + int n = 2; + int m = 1; + double _ = 0.4444444444444444; +END +CASE(1) + int n = 2; + int m = 2; + double _ = 0.5555555555555556; +END +CASE(2) + int n = 1; + int m = 1; + double _ = 1.0; +END +CASE(3) + int n = 3; + int m = 2; + double _ = 0.31746031746031744; +END +CASE(4) + int n = 1000; + int m = 500; + double _ = -1; +END +CASE(5) + int n = 1; + int m = 1; + double _ = 1.0; +END +CASE(6) + int n = 1000; + int m = 1000; + double _ = -1; +END +CASE(7) + int n = 1000; + int m = 1; + double _ = -1; +END + +} +// END CUT HERE