Artifact 4250c24f458f28d744a459d59f997ca895b8628d
#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;
class Pillars { public:
double getExpectedLength(int w, int x, int y)
{
if(x>y) swap(x,y);
double e = 0;
int num = 1;
for(int y_minus_x=1-x; y_minus_x<=y-1; ++y_minus_x) {
e += hypot(y_minus_x, w) * num;
if(y_minus_x<0)
++num;
else if(y_minus_x >= y-x)
--num;
}
return e/y/x;
}
};
// 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(_, Pillars().getExpectedLength(w, x, y));}
int main(){
CASE(0)
int w = 1;
int x = 1;
int y = 1;
double _ = 1.0;
END
CASE(1)
int w = 1;
int x = 5;
int y = 1;
double _ = 2.387132965131785;
END
CASE(1)
int w = 1;
int x = 1;
int y = 5;
double _ = 2.387132965131785;
END
CASE(2)
int w = 2;
int x = 3;
int y = 15;
double _ = 6.737191281760445;
END
CASE(2)
int w = 2;
int x = 15;
int y = 3;
double _ = 6.737191281760445;
END
CASE(3)
int w = 10;
int x = 15;
int y = 23;
double _ = 12.988608956320535;
END
CASE(3)
int w = 10;
int x = 23;
int y = 15;
double _ = 12.988608956320535;
END
CASE(4)
int w = 1000;
int x = 100000;
int y = 100000;
double _ = -1;
END
CASE(5)
int w = 1;
int x = 1;
int y = 1;
double _ = 1;
END
}
// END CUT HERE