854327905b 2014-12-27 kinaba: #include <iostream> 854327905b 2014-12-27 kinaba: #include <sstream> 854327905b 2014-12-27 kinaba: #include <iomanip> 854327905b 2014-12-27 kinaba: #include <vector> 854327905b 2014-12-27 kinaba: #include <string> 854327905b 2014-12-27 kinaba: #include <map> 854327905b 2014-12-27 kinaba: #include <set> 854327905b 2014-12-27 kinaba: #include <algorithm> 854327905b 2014-12-27 kinaba: #include <numeric> 854327905b 2014-12-27 kinaba: #include <iterator> 854327905b 2014-12-27 kinaba: #include <functional> 854327905b 2014-12-27 kinaba: #include <complex> 854327905b 2014-12-27 kinaba: #include <queue> 854327905b 2014-12-27 kinaba: #include <stack> 854327905b 2014-12-27 kinaba: #include <cmath> 854327905b 2014-12-27 kinaba: #include <cassert> 854327905b 2014-12-27 kinaba: #include <tuple> 854327905b 2014-12-27 kinaba: using namespace std; 854327905b 2014-12-27 kinaba: typedef long long LL; 854327905b 2014-12-27 kinaba: typedef complex<double> CMP; 854327905b 2014-12-27 kinaba: 854327905b 2014-12-27 kinaba: class WaitingForBus { public: 854327905b 2014-12-27 kinaba: double whenWillBusArrive(vector <int> time, vector <int> prob, int s) 854327905b 2014-12-27 kinaba: { 854327905b 2014-12-27 kinaba: const int WAIT_TIME_MAX = 100000; 854327905b 2014-12-27 kinaba: 854327905b 2014-12-27 kinaba: deque<double> p(WAIT_TIME_MAX+1, 0.0); 854327905b 2014-12-27 kinaba: p[0] = 1.0; 854327905b 2014-12-27 kinaba: for(int t=1; t<=s; ++t) { 854327905b 2014-12-27 kinaba: double p0 = p[0]; 854327905b 2014-12-27 kinaba: p.pop_front(); 854327905b 2014-12-27 kinaba: p.push_back(0.0); 854327905b 2014-12-27 kinaba: for(int i=0; i<time.size(); ++i) 854327905b 2014-12-27 kinaba: p[time[i]-1] += p0 * prob[i] / 100; 854327905b 2014-12-27 kinaba: } 854327905b 2014-12-27 kinaba: 854327905b 2014-12-27 kinaba: double ans = 0.0; 854327905b 2014-12-27 kinaba: for(int t=0; t<=WAIT_TIME_MAX; ++t) 854327905b 2014-12-27 kinaba: ans += t * p[t]; 854327905b 2014-12-27 kinaba: return ans; 854327905b 2014-12-27 kinaba: } 854327905b 2014-12-27 kinaba: }; 854327905b 2014-12-27 kinaba: 854327905b 2014-12-27 kinaba: // BEGIN CUT HERE 854327905b 2014-12-27 kinaba: #include <ctime> 854327905b 2014-12-27 kinaba: double start_time; string timer() 854327905b 2014-12-27 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 854327905b 2014-12-27 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 854327905b 2014-12-27 kinaba: { os << "{ "; 854327905b 2014-12-27 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 854327905b 2014-12-27 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 854327905b 2014-12-27 kinaba: void verify_case(const double& Expected, const double& Received) { 854327905b 2014-12-27 kinaba: bool ok = (abs(Expected - Received) < 1e-9); 854327905b 2014-12-27 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 854327905b 2014-12-27 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 854327905b 2014-12-27 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 854327905b 2014-12-27 kinaba: #define END verify_case(_, WaitingForBus().whenWillBusArrive(time, prob, s));} 854327905b 2014-12-27 kinaba: int main(){ 854327905b 2014-12-27 kinaba: 854327905b 2014-12-27 kinaba: CASE(0) 854327905b 2014-12-27 kinaba: int time_[] = {5,100}; 854327905b 2014-12-27 kinaba: vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 854327905b 2014-12-27 kinaba: int prob_[] = {90,10}; 854327905b 2014-12-27 kinaba: vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 854327905b 2014-12-27 kinaba: int s = 5; 854327905b 2014-12-27 kinaba: double _ = 9.5; 854327905b 2014-12-27 kinaba: END 854327905b 2014-12-27 kinaba: CASE(1) 854327905b 2014-12-27 kinaba: int time_[] = {5}; 854327905b 2014-12-27 kinaba: vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 854327905b 2014-12-27 kinaba: int prob_[] = {100}; 854327905b 2014-12-27 kinaba: vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 854327905b 2014-12-27 kinaba: int s = 101; 854327905b 2014-12-27 kinaba: double _ = 4.0; 854327905b 2014-12-27 kinaba: END 854327905b 2014-12-27 kinaba: CASE(2) 854327905b 2014-12-27 kinaba: int time_[] = {5,10}; 854327905b 2014-12-27 kinaba: vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 854327905b 2014-12-27 kinaba: int prob_[] = {50,50}; 854327905b 2014-12-27 kinaba: vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 854327905b 2014-12-27 kinaba: int s = 88888; 854327905b 2014-12-27 kinaba: double _ = 3.666666666666667; 854327905b 2014-12-27 kinaba: END 854327905b 2014-12-27 kinaba: CASE(3) 854327905b 2014-12-27 kinaba: int time_[] = {1,2,3,4}; 854327905b 2014-12-27 kinaba: vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 854327905b 2014-12-27 kinaba: int prob_[] = {10,20,30,40}; 854327905b 2014-12-27 kinaba: vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 854327905b 2014-12-27 kinaba: int s = 1000; 854327905b 2014-12-27 kinaba: double _ = 1.166666666666667; 854327905b 2014-12-27 kinaba: END 854327905b 2014-12-27 kinaba: CASE(4) 854327905b 2014-12-27 kinaba: int time_[] = {10,100,1000,10000,100000}; 854327905b 2014-12-27 kinaba: vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 854327905b 2014-12-27 kinaba: int prob_[] = {90,4,3,2,1}; 854327905b 2014-12-27 kinaba: vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 854327905b 2014-12-27 kinaba: int s = 100000; 854327905b 2014-12-27 kinaba: double _ = 21148.147303578935; 854327905b 2014-12-27 kinaba: END 854327905b 2014-12-27 kinaba: /* 854327905b 2014-12-27 kinaba: CASE(5) 854327905b 2014-12-27 kinaba: int time_[] = ; 854327905b 2014-12-27 kinaba: vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 854327905b 2014-12-27 kinaba: int prob_[] = ; 854327905b 2014-12-27 kinaba: vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 854327905b 2014-12-27 kinaba: int s = ; 854327905b 2014-12-27 kinaba: double _ = ; 854327905b 2014-12-27 kinaba: END 854327905b 2014-12-27 kinaba: CASE(6) 854327905b 2014-12-27 kinaba: int time_[] = ; 854327905b 2014-12-27 kinaba: vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 854327905b 2014-12-27 kinaba: int prob_[] = ; 854327905b 2014-12-27 kinaba: vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 854327905b 2014-12-27 kinaba: int s = ; 854327905b 2014-12-27 kinaba: double _ = ; 854327905b 2014-12-27 kinaba: END 854327905b 2014-12-27 kinaba: */ 854327905b 2014-12-27 kinaba: } 854327905b 2014-12-27 kinaba: // END CUT HERE