Artifact Content
Not logged in

Artifact 2ec89edcc9c2afbe1b669d358e3b207c97713f0f


#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 AliceAndFriends { public:
	double getMoney(vector <int> cards)
	{
		int N = cards.size();
		double ex = 0.0;
		for(int alice=0; alice<N; ++alice)
		{
			double best = -1e+300;

			int R = cards[alice];
			for(int B=0; B<=R; ++B)
			{
				double total_gain = 0.0;
				for(int i=0; i<N; ++i) if(i!=alice)
				{
					int r = cards[i];
					double best_you = 1e+300;
					int b;
					if(R==r)
						b = B;
					else if(R < r)
						b = 0;
					else {
					}

					// r-b > R-B
					// r-b > R+B
					// r+b > R-B
					// r+b > R+B
					// ができるだけ成り立ちたい
					for(int b=0; b<=r; ++b)
					{
						// Alice: [R-B or R+B]
						// You: [r-b or r+b]
						double s = 0.0;
						s += (r-b<R-B ? +0.25 : r-b>R-B ? -0.25 : 0);
						s += (r-b<R+B ? +0.25 : r-b>R+B ? -0.25 : 0);
						s += (r+b<R-B ? +0.25 : r+b>R-B ? -0.25 : 0);
						s += (r+b<R+B ? +0.25 : r+b>R+B ? -0.25 : 0);
						best_you = min(best_you, s);
					}
					total_gain += best_you;
				}
				best = max(best, total_gain);
			}
			ex += best;
		}
		return ex / N;
	}
};

// 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(_, AliceAndFriends().getMoney(cards));}
int main(){

CASE(0)
	int cards_[] = {10, 1};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	double _ = 0.0; 
END
CASE(1)
	int cards_[] = {10, 9};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	double _ = -0.25; 
END
CASE(2)
	int cards_[] = {1, 3};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	double _ = 0.0; 
END
CASE(3)
	int cards_[] = {1000000000, 1000000000};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	double _ = 0.0; 
END
CASE(4)
	int cards_[] = {42, 468, 335, 501, 170, 725, 479, 359, 963, 465, 706, 146, 282, 828, 962, 492, 996,
 943, 828, 437, 392, 605, 903, 154, 293, 383, 422, 717, 719, 896, 448, 727, 772, 539,
 870, 913, 668, 300, 36, 895, 704, 812, 323, 334, 674, 665, 142, 712, 254, 869};
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	double _ = -9.095; 
END
/*
CASE(5)
	int cards_[] = ;
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	double _ = ; 
END
CASE(6)
	int cards_[] = ;
	  vector <int> cards(cards_, cards_+sizeof(cards_)/sizeof(*cards_)); 
	double _ = ; 
END
*/
}
// END CUT HERE