e874ae142a 2015-07-10 kinaba: #include <iostream> e874ae142a 2015-07-10 kinaba: #include <sstream> e874ae142a 2015-07-10 kinaba: #include <iomanip> e874ae142a 2015-07-10 kinaba: #include <vector> e874ae142a 2015-07-10 kinaba: #include <string> e874ae142a 2015-07-10 kinaba: #include <map> e874ae142a 2015-07-10 kinaba: #include <set> e874ae142a 2015-07-10 kinaba: #include <algorithm> e874ae142a 2015-07-10 kinaba: #include <numeric> e874ae142a 2015-07-10 kinaba: #include <iterator> e874ae142a 2015-07-10 kinaba: #include <functional> e874ae142a 2015-07-10 kinaba: #include <complex> e874ae142a 2015-07-10 kinaba: #include <queue> e874ae142a 2015-07-10 kinaba: #include <stack> e874ae142a 2015-07-10 kinaba: #include <cmath> e874ae142a 2015-07-10 kinaba: #include <cassert> e874ae142a 2015-07-10 kinaba: #include <tuple> e874ae142a 2015-07-10 kinaba: using namespace std; e874ae142a 2015-07-10 kinaba: typedef long long LL; e874ae142a 2015-07-10 kinaba: typedef complex<double> CMP; e874ae142a 2015-07-10 kinaba: e874ae142a 2015-07-10 kinaba: class Bitwisdom { public: e874ae142a 2015-07-10 kinaba: double expectedActions(vector <int> p) e874ae142a 2015-07-10 kinaba: { e874ae142a 2015-07-10 kinaba: double e = 0; e874ae142a 2015-07-10 kinaba: for(int i=1; i<p.size(); ++i) { e874ae142a 2015-07-10 kinaba: e += (p[i]/100.0) * (100-p[i-1])/100.0 e874ae142a 2015-07-10 kinaba: + (p[i-1]/100.0) * (100-p[i])/100.0; e874ae142a 2015-07-10 kinaba: } e874ae142a 2015-07-10 kinaba: double q = 1.0; e874ae142a 2015-07-10 kinaba: for(int i=0; i<p.size(); ++i) e874ae142a 2015-07-10 kinaba: q *= (p[i]/100.0); e874ae142a 2015-07-10 kinaba: return e + q; e874ae142a 2015-07-10 kinaba: } e874ae142a 2015-07-10 kinaba: }; e874ae142a 2015-07-10 kinaba: e874ae142a 2015-07-10 kinaba: // BEGIN CUT HERE e874ae142a 2015-07-10 kinaba: #include <ctime> e874ae142a 2015-07-10 kinaba: double start_time; string timer() e874ae142a 2015-07-10 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } e874ae142a 2015-07-10 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) e874ae142a 2015-07-10 kinaba: { os << "{ "; e874ae142a 2015-07-10 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) e874ae142a 2015-07-10 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } e874ae142a 2015-07-10 kinaba: void verify_case(const double& Expected, const double& Received) { e874ae142a 2015-07-10 kinaba: bool ok = (abs(Expected - Received) < 1e-9); e874ae142a 2015-07-10 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; e874ae142a 2015-07-10 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } e874ae142a 2015-07-10 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); e874ae142a 2015-07-10 kinaba: #define END verify_case(_, Bitwisdom().expectedActions(p));} e874ae142a 2015-07-10 kinaba: int main(){ e874ae142a 2015-07-10 kinaba: e874ae142a 2015-07-10 kinaba: CASE(0) e874ae142a 2015-07-10 kinaba: int p_[] = {100, 100, 100}; e874ae142a 2015-07-10 kinaba: vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); e874ae142a 2015-07-10 kinaba: double _ = 1.0; e874ae142a 2015-07-10 kinaba: END e874ae142a 2015-07-10 kinaba: CASE(1) e874ae142a 2015-07-10 kinaba: int p_[] = {50, 50}; e874ae142a 2015-07-10 kinaba: vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); e874ae142a 2015-07-10 kinaba: double _ = 0.75; e874ae142a 2015-07-10 kinaba: END e874ae142a 2015-07-10 kinaba: CASE(2) e874ae142a 2015-07-10 kinaba: int p_[] = {0, 40, 50, 60}; e874ae142a 2015-07-10 kinaba: vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); e874ae142a 2015-07-10 kinaba: double _ = 1.4; e874ae142a 2015-07-10 kinaba: END e874ae142a 2015-07-10 kinaba: CASE(3) e874ae142a 2015-07-10 kinaba: int p_[] = {37, 63, 23, 94, 12}; e874ae142a 2015-07-10 kinaba: vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); e874ae142a 2015-07-10 kinaba: double _ = 2.6820475464; e874ae142a 2015-07-10 kinaba: END e874ae142a 2015-07-10 kinaba: /* e874ae142a 2015-07-10 kinaba: CASE(4) e874ae142a 2015-07-10 kinaba: int p_[] = ; e874ae142a 2015-07-10 kinaba: vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); e874ae142a 2015-07-10 kinaba: double _ = ; e874ae142a 2015-07-10 kinaba: END e874ae142a 2015-07-10 kinaba: CASE(5) e874ae142a 2015-07-10 kinaba: int p_[] = ; e874ae142a 2015-07-10 kinaba: vector <int> p(p_, p_+sizeof(p_)/sizeof(*p_)); e874ae142a 2015-07-10 kinaba: double _ = ; e874ae142a 2015-07-10 kinaba: END e874ae142a 2015-07-10 kinaba: */ e874ae142a 2015-07-10 kinaba: } e874ae142a 2015-07-10 kinaba: // END CUT HERE