d921147eef 2012-07-01 kinaba: #include <iostream> d921147eef 2012-07-01 kinaba: #include <sstream> d921147eef 2012-07-01 kinaba: #include <iomanip> d921147eef 2012-07-01 kinaba: #include <vector> d921147eef 2012-07-01 kinaba: #include <string> d921147eef 2012-07-01 kinaba: #include <map> d921147eef 2012-07-01 kinaba: #include <set> d921147eef 2012-07-01 kinaba: #include <algorithm> d921147eef 2012-07-01 kinaba: #include <numeric> d921147eef 2012-07-01 kinaba: #include <iterator> d921147eef 2012-07-01 kinaba: #include <functional> d921147eef 2012-07-01 kinaba: #include <complex> d921147eef 2012-07-01 kinaba: #include <queue> d921147eef 2012-07-01 kinaba: #include <stack> d921147eef 2012-07-01 kinaba: #include <cmath> d921147eef 2012-07-01 kinaba: #include <cassert> d921147eef 2012-07-01 kinaba: using namespace std; d921147eef 2012-07-01 kinaba: typedef long long LL; d921147eef 2012-07-01 kinaba: typedef long double LD; d921147eef 2012-07-01 kinaba: typedef complex<LD> CMP; d921147eef 2012-07-01 kinaba: d921147eef 2012-07-01 kinaba: class Pillars { public: d921147eef 2012-07-01 kinaba: double getExpectedLength(int w, int x, int y) d921147eef 2012-07-01 kinaba: { d921147eef 2012-07-01 kinaba: if(x>y) swap(x,y); d921147eef 2012-07-01 kinaba: d921147eef 2012-07-01 kinaba: double e = 0; d921147eef 2012-07-01 kinaba: int num = 1; d921147eef 2012-07-01 kinaba: for(int y_minus_x=1-x; y_minus_x<=y-1; ++y_minus_x) { d921147eef 2012-07-01 kinaba: e += hypot(y_minus_x, w) * num; d921147eef 2012-07-01 kinaba: if(y_minus_x<0) d921147eef 2012-07-01 kinaba: ++num; d921147eef 2012-07-01 kinaba: else if(y_minus_x >= y-x) d921147eef 2012-07-01 kinaba: --num; d921147eef 2012-07-01 kinaba: } d921147eef 2012-07-01 kinaba: return e/y/x; d921147eef 2012-07-01 kinaba: } d921147eef 2012-07-01 kinaba: }; d921147eef 2012-07-01 kinaba: d921147eef 2012-07-01 kinaba: // BEGIN CUT HERE d921147eef 2012-07-01 kinaba: #include <ctime> d921147eef 2012-07-01 kinaba: double start_time; string timer() d921147eef 2012-07-01 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } d921147eef 2012-07-01 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) d921147eef 2012-07-01 kinaba: { os << "{ "; d921147eef 2012-07-01 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) d921147eef 2012-07-01 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } d921147eef 2012-07-01 kinaba: void verify_case(const double& Expected, const double& Received) { d921147eef 2012-07-01 kinaba: bool ok = (abs(Expected - Received) < 1e-9); d921147eef 2012-07-01 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; d921147eef 2012-07-01 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } d921147eef 2012-07-01 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); d921147eef 2012-07-01 kinaba: #define END verify_case(_, Pillars().getExpectedLength(w, x, y));} d921147eef 2012-07-01 kinaba: int main(){ d921147eef 2012-07-01 kinaba: CASE(0) d921147eef 2012-07-01 kinaba: int w = 1; d921147eef 2012-07-01 kinaba: int x = 1; d921147eef 2012-07-01 kinaba: int y = 1; d921147eef 2012-07-01 kinaba: double _ = 1.0; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(1) d921147eef 2012-07-01 kinaba: int w = 1; d921147eef 2012-07-01 kinaba: int x = 5; d921147eef 2012-07-01 kinaba: int y = 1; d921147eef 2012-07-01 kinaba: double _ = 2.387132965131785; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(1) d921147eef 2012-07-01 kinaba: int w = 1; d921147eef 2012-07-01 kinaba: int x = 1; d921147eef 2012-07-01 kinaba: int y = 5; d921147eef 2012-07-01 kinaba: double _ = 2.387132965131785; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(2) d921147eef 2012-07-01 kinaba: int w = 2; d921147eef 2012-07-01 kinaba: int x = 3; d921147eef 2012-07-01 kinaba: int y = 15; d921147eef 2012-07-01 kinaba: double _ = 6.737191281760445; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(2) d921147eef 2012-07-01 kinaba: int w = 2; d921147eef 2012-07-01 kinaba: int x = 15; d921147eef 2012-07-01 kinaba: int y = 3; d921147eef 2012-07-01 kinaba: double _ = 6.737191281760445; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(3) d921147eef 2012-07-01 kinaba: int w = 10; d921147eef 2012-07-01 kinaba: int x = 15; d921147eef 2012-07-01 kinaba: int y = 23; d921147eef 2012-07-01 kinaba: double _ = 12.988608956320535; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(3) d921147eef 2012-07-01 kinaba: int w = 10; d921147eef 2012-07-01 kinaba: int x = 23; d921147eef 2012-07-01 kinaba: int y = 15; d921147eef 2012-07-01 kinaba: double _ = 12.988608956320535; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(4) d921147eef 2012-07-01 kinaba: int w = 1000; d921147eef 2012-07-01 kinaba: int x = 100000; d921147eef 2012-07-01 kinaba: int y = 100000; d921147eef 2012-07-01 kinaba: double _ = -1; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: CASE(5) d921147eef 2012-07-01 kinaba: int w = 1; d921147eef 2012-07-01 kinaba: int x = 1; d921147eef 2012-07-01 kinaba: int y = 1; d921147eef 2012-07-01 kinaba: double _ = 1; d921147eef 2012-07-01 kinaba: END d921147eef 2012-07-01 kinaba: d921147eef 2012-07-01 kinaba: } d921147eef 2012-07-01 kinaba: // END CUT HERE