Artifact 0013ea53e2a547800e17b04a9efea73a7f8ed944
#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class LateProfessor { public:
double getProbability(int waitTime, int walkTime, int lateTime, int bestArrival, int worstArrival)
{
if( worstArrival - bestArrival == 0 )
{
int t = bestArrival % (waitTime+walkTime);
if( t<=waitTime )
return 0;
if( t+lateTime <= waitTime+walkTime )
return 1;
return 0;
}
if( walkTime <= lateTime )
return 0;
int bad = 0;
for(int t=0; t<=worstArrival; t+=waitTime+walkTime)
{
int tb = max(bestArrival, t+waitTime);
int te = min(worstArrival, t+waitTime+walkTime-lateTime);
if( tb < te )
bad += te - tb;
}
return double(bad) / (worstArrival - bestArrival);
}
};
// 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(_, LateProfessor().getProbability(waitTime, walkTime, lateTime, bestArrival, worstArrival));}
int main(){
CASE(0)
int waitTime = 20;
int walkTime = 30;
int lateTime = 10;
int bestArrival = 0;
int worstArrival = 50;
double _ = 0.4;
END
CASE(1)
int waitTime = 20;
int walkTime = 30;
int lateTime = 10;
int bestArrival = 30;
int worstArrival = 100;
double _ = 0.42857142857142855;
END
CASE(2)
int waitTime = 20;
int walkTime = 40;
int lateTime = 50;
int bestArrival = 0;
int worstArrival = 300;
double _ = 0.0;
END
CASE(3)
int waitTime = 101;
int walkTime = 230;
int lateTime = 10;
int bestArrival = 654;
int worstArrival = 17890;
double _ = 0.6637270828498492;
END
CASE(4)
int waitTime = 20;
int walkTime = 30;
int lateTime = 10;
int bestArrival = 90;
int worstArrival = 90;
double _ = 1.0;
END
CASE(5)
int waitTime = 1000;
int walkTime = 600;
int lateTime = 1;
int bestArrival = 17000;
int worstArrival = 17000;
double _ = 0.0;
END
CASE(6)
int waitTime = 1;
int walkTime = 2;
int lateTime = 1;
int bestArrival = 2;
int worstArrival = 2;
double _ = -1;
END
CASE(7)
int waitTime = 1000;
int walkTime = 1000;
int lateTime = 1000;
int bestArrival = 0;
int worstArrival = 10000000;
double _ = -1;
END
}
// END CUT HERE