Artifact Content
Not logged in

Artifact 7ca249caa65bea302e9180a95777e2487655ab4b


#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 AlternatingLane { public:
	double expectedBeauty(vector <int> low, vector <int> high) 
	{
		double eSum = 0.0;
		for(int i=1; i<low.size(); ++i)
		{
			// ランダムに
			//   h ∈ [low[i-1], high[i-1]]
			//   g ∈ [low[i],   high[i]  ]
			// を取ってきたときの、|h-g| の期待値…
			double e = 0;
			for(int h=low[i-1]; h<=high[i-1]; ++h)
				if( h <= low[i] )
					e += sequenceSum(low[i]-h, high[i]-h);
				else if( high[i] <= h )
					e += sequenceSum(h-high[i], h-low[i]);
				else
					e += sequenceSum(0, h-low[i]) + sequenceSum(0, high[i]-h);
			eSum += e / (high[i]-low[i]+1) / (high[i-1]-low[i-1]+1);
		}
		return eSum; // …の和、が答え
	}

	LL sequenceSum(LL a, LL b) // a+(a+1)+...+b
	{
		return (a+b) * (b-a+1) / 2;
	}
};

// 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(_, AlternatingLane().expectedBeauty(low, high));}
int main(){

CASE(0)
	int low_[] = {1};
	  vector <int> low(low_, low_+sizeof(low_)/sizeof(*low_)); 
	int high_[] = {100};
	  vector <int> high(high_, high_+sizeof(high_)/sizeof(*high_)); 
	double _ = 0.0; 
END
CASE(1)
	int low_[] = {1, 1, 1};
	  vector <int> low(low_, low_+sizeof(low_)/sizeof(*low_)); 
	int high_[] = {2, 2, 2};
	  vector <int> high(high_, high_+sizeof(high_)/sizeof(*high_)); 
	double _ = 1.0; 
END
CASE(2)
	int low_[] = {1, 3, 5, 7, 9};
	  vector <int> low(low_, low_+sizeof(low_)/sizeof(*low_)); 
	int high_[] = {2, 4, 6, 8, 10};
	  vector <int> high(high_, high_+sizeof(high_)/sizeof(*high_)); 
	double _ = 8.0; 
END
CASE(3)
	int low_[] = {4, 3, 3, 7};
	  vector <int> low(low_, low_+sizeof(low_)/sizeof(*low_)); 
	int high_[] = {10, 7, 7, 7};
	  vector <int> high(high_, high_+sizeof(high_)/sizeof(*high_)); 
	double _ = 6.171428571428572; 
END
CASE(4)
int low_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
	  vector <int> low(low_, low_+sizeof(low_)/sizeof(*low_)); 
	  int high_[] = {100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000};
	  vector <int> high(high_, high_+sizeof(high_)/sizeof(*high_)); 
	double _ = -1; 
END
/*
CASE(5)
	int low_[] = ;
	  vector <int> low(low_, low_+sizeof(low_)/sizeof(*low_)); 
	int high_[] = ;
	  vector <int> high(high_, high_+sizeof(high_)/sizeof(*high_)); 
	double _ = ; 
END
*/
}
// END CUT HERE