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