Artifact Content
Not logged in

Artifact 9ba46fb7593c506ad2e5f345c239337d8bff1566


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class WaitingForBus { public:
	double whenWillBusArrive(vector <int> time, vector <int> prob, int s)
	{
		const int WAIT_TIME_MAX = 100000;

		deque<double> p(WAIT_TIME_MAX+1, 0.0);
		p[0] = 1.0;
		for(int t=1; t<=s; ++t) {
			double p0 = p[0];
			p.pop_front();
			p.push_back(0.0);
			for(int i=0; i<time.size(); ++i)
				p[time[i]-1] += p0 * prob[i] / 100;
		}

		double ans = 0.0;
		for(int t=0; t<=WAIT_TIME_MAX; ++t)
			ans += t * p[t];
		return ans;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::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(_, WaitingForBus().whenWillBusArrive(time, prob, s));}
int main(){

CASE(0)
	int time_[] = {5,100};
	  vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 
	int prob_[] = {90,10};
	  vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 
	int s = 5; 
	double _ = 9.5; 
END
CASE(1)
	int time_[] = {5};
	  vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 
	int prob_[] = {100};
	  vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 
	int s = 101; 
	double _ = 4.0; 
END
CASE(2)
	int time_[] = {5,10};
	  vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 
	int prob_[] = {50,50};
	  vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 
	int s = 88888; 
	double _ = 3.666666666666667; 
END
CASE(3)
	int time_[] = {1,2,3,4};
	  vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 
	int prob_[] = {10,20,30,40};
	  vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 
	int s = 1000; 
	double _ = 1.166666666666667; 
END
CASE(4)
	int time_[] = {10,100,1000,10000,100000};
	  vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 
	int prob_[] = {90,4,3,2,1};
	  vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 
	int s = 100000; 
	double _ = 21148.147303578935; 
END
/*
CASE(5)
	int time_[] = ;
	  vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 
	int prob_[] = ;
	  vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 
	int s = ; 
	double _ = ; 
END
CASE(6)
	int time_[] = ;
	  vector <int> time(time_, time_+sizeof(time_)/sizeof(*time_)); 
	int prob_[] = ;
	  vector <int> prob(prob_, prob_+sizeof(prob_)/sizeof(*prob_)); 
	int s = ; 
	double _ = ; 
END
*/
}
// END CUT HERE